pylint导入和动态路径修改
我的项目通常是这样构造的:
projectname/
__init__.py
python/
mymodule.py
other_stuff/
more_stuff/
其中 __init__.py
包含以下代码
import os
mypath = os.path.dirname(os.path.realpath(os.path.abspath(__file__)))
__path__ = [mypath, mypath+"/python"]
导入时“跳过”python
目录,以允许采用 from 形式的 python 代码projectname import mymodule
而不是 from projectname.python import mymodule
。
然而,这似乎破坏了 pylint,尽管 $PYTHONPATH
设置正确,但无法导入项目中的任何模块。创建软链接 projectname ->
修复了一些问题,但不是合适的解决方案。projectname
中的 python
关于如何在不改变目录结构的情况下解决这个问题有什么建议吗?
My projects are generally structured like this:
projectname/
__init__.py
python/
mymodule.py
other_stuff/
more_stuff/
where __init__.py
contains the following code
import os
mypath = os.path.dirname(os.path.realpath(os.path.abspath(__file__)))
__path__ = [mypath, mypath+"/python"]
This "skips" the python
directory when importing to allow python code in the form from projectname import mymodule
rather than from projectname.python import mymodule
.
This appears to break pylint however, being unable to import any modules in the project despite $PYTHONPATH
being set correctly. Creating a softlink projectname -> python
in the projectname
fixes things but isn't a suitable solution.
Any suggestions on how to fix this without altering the directory structure?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我觉得你有点被困住了。 Pylint 不会处理您的 __init__.py 文件,因此除非您能找到另一种方法将该信息输入 pylint,否则我认为它不会起作用。祝你好运。
I think you're kind of stuck. Pylint doesn't process your __init__.py file so unless you can find another way of getting that information into pylint, I don't think it's going to work. Good luck.