Search code examples
pythonpython-3.xvisual-studio-codepylint

VScode python 3 pylint: I can import X file in A but not B


I'm using the latest version of VScode, using pylint and python 3. I'm using I'm on Ubuntu 16.04 and virtualenv. I can import all python and pip packages correctly, I only face the error when working with files I created.

I have 3 files, all are next to each other sitting in the same folder. a.py, b.py and keys.py, the latter contains nothing but keys as strings.

in a.py, I can do

from keys import X

But in b.py pylint doesn't let me do that, I get

Unable to import 'keys' [E0401]

I can only do

from .keys import X

Which is wrong but I mean that would remove the error above.


Solution

  • The issue is that Pylint is seeing the files as contained in a package (hence the relative import of from .keys import X working). Trying to execute a.py directly is kind of "cheating" by trying to view the files as not in a package.