I'm running PyLint from inside Wing IDE on Windows. I have a sub-directory (package) in my project and inside the package I import a module from the top level, ie.
__init__.py
myapp.py
one.py
subdir\
__init__.py
two.py
Inside two.py
I have import one
and this works fine at runtime, because the top-level directory (from which myapp.py
is run) is in the Python path. However, when I run PyLint on two.py it gives me an error:
F0401: Unable to import 'one'
How do I fix this?
I had this same issue and fixed it by installing pylint in my virtualenv and then adding a .pylintrc file to my project directory with the following in the file:
1) sys.path is a list.
2) The problem is sometimes the sys.path is not your virtualenv.path and you want to use pylint in your virtualenv
3) So like said, use init-hook (pay attention in ' and " the parse of pylint is strict)
or
.. and
I had to update the system
PYTHONPATH
variable to add my App Engine path. In my case I just had to edit my~/.bashrc
file and add the following line:export PYTHONPATH=$PYTHONPATH:/path/to/google_appengine_folder
In fact, I tried setting the
init-hook
first but this did not resolve the issue consistently across my code base (not sure why). Once I added it to the system path (probably a good idea in general) my issues went away.I had the same problem and since i could not find a answer I hope this can help anyone with a similar problem.
I use flymake with epylint. Basically what i did was add a dired-mode-hook that check if the dired directory is a python package directory. If it is I add it to the PYTHONPATH. In my case I consider a directory to be a python package if it contains a file named "setup.py".
Hope this helps.
if you using vscode,make sure your package directory is out of the _pychache__ directory.
The solution to alter path in
init-hook
is good, but I dislike the fact that I had to add absolute path there, as result I can not share this pylintrc file among the developers of the project. This solution using relative path to pylintrc file works better for me:Note that
pylint.config.PYLINTRC
also exists and has the same value asfind_pylintrc()
.