PyLint & ldquo; Unable to import & rdquo; error - how to configure 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?

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.