pylint import and dynamic path modification

元气小坏坏 提交于 2019-12-08 04:42:44

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/5394786/pylint-import-and-dynamic-path-modification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!