PyLint "Unable to import" error - how to set PYTHONPATH?


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.

Inside I have import one and this works fine at runtime, because the top-level directory (from which is run) is in the Python path. However, when I run PyLint on it gives me an error:

F0401: Unable to import 'one'

How do I fix this?

4/1/2015 8:46:03 AM

There are two options I'm aware of.

One, change the PYTHONPATH environment variable to include the directory above your module.

Alternatively, edit ~/.pylintrc to include the directory above your module, like this:

init-hook='import sys; sys.path.append("/path/to/root")'

(Or in other version of pylint, the init-hook requires you to change [General] to [MASTER])

Both of these options ought to work.

Hope that helps.

1/26/2018 10:30:01 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow