简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM