San*_*ta7 8 python python-import jupyter-notebook google-colaboratory
我试图让我的代码可以从 Github 安装。
在我的 github 文件夹中,我有一些具有相对导入的脚本。我尝试运行脚本,但出现错误。
根据这个SO question Run script within python package
编辑 - 如果您的 script.py 使用相对导入(并且您不想更改它),那么除了将该根路径放入环境之外,别无他法。如果需要,您可以在脚本中执行此操作,而不是在 cmd shell 或批处理文件中进行设置。但它需要在某个地方完成。以下是在脚本中设置环境路径的方法:
import sys
sys.path.append(r'..\..\path\to\my\package')
import package.other.anotherscript
Run Code Online (Sandbox Code Playgroud)
所以现在我想弄清楚我安装的 Github 的路径是什么,但我似乎找不到它。它似乎已正确安装,但它只是不存在。
这是我的 Github
https://github.com/Santosh-Gupta/MedicalQA
这些是我的脚本,它们具有相对导入
https://github.com/Santosh-Gupta/MedicalQA/tree/master/Scripts
这是我用来安装我的 Github 的。
!pip install https://github.com/Santosh-Gupta/MedicalQA/archive/master.zip
Run Code Online (Sandbox Code Playgroud)
我尝试使用
print(sys.path)
os.listdir('lib')
os.listdir('lib/python3.6')
os.listdir('lib/python3.6/site-packages')
Run Code Online (Sandbox Code Playgroud)
任何其他用于获取具有相对导入的脚本和代码以在 python 包中工作的信息将不胜感激。