【发布时间】:2017-11-27 16:56:25
【问题描述】:
所以。我知道这个问题似乎已经被问死了,但似乎没有一个答案能解决我想要做什么。
我在另一个目录中有一个库,我想将它包含在我运行的一组 other 项目中。我不希望每次运行 python 时都添加那个库。
所以,我 一直在我的 python 代码中这样做:
import sys
sys.path.append("/tmp/demo/src/my-lib")
import MyClass
这很好用。但是,现在我发现并喜欢 pylint,它抱怨说
E: 7, 0: Unable to import 'MyClass' (import-error)
C: 7, 0: Import "import MyClass" should be placed at the top of the module (wrong-import-position)
我知道我可以使用指令禁用 import-error 和 wrong-import-position(或者只是将其放入 .pylintrc ...)但是,我宁愿不这样做。我想知道将路径添加到 sys.path 的“正确”方式,该路径不是 global 我的项目,只是添加到使用它的项目子集特定的图书馆。
这可能吗?
【问题讨论】: