pylint 导入和动态路径修改 [英] pylint import and dynamic path modification
问题描述
我的项目结构通常是这样的:
My projects are generally structured like this:
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 projectname import mymodule
而不是 from projectname.python import mymodule
形式的 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
.
这似乎破坏了 pylint,尽管 $PYTHONPATH
设置正确,但无法导入项目中的任何模块.创建软链接 projectname ->
修复了一些问题,但不是一个合适的解决方案.projectname
中的 python
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?
推荐答案
我觉得你有点卡住了.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.
这篇关于pylint 导入和动态路径修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!