简体   繁体   English

VScode python 3 pylint:我可以在A中导入X文件,但不能在B中导入

[英]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. 我正在使用最新版本的VScode,同时使用pylint和python3。我正在Ubuntu 16.04和virtualenv上使用。 I can import all python and pip packages correctly, I only face the error when working with files I created. 我可以正确导入所有python和pip包,只有在处理我创建的文件时才会遇到错误。

I have 3 files, all are next to each other sitting in the same folder. 我有3个文件,所有文件都相邻放置在同一文件夹中。 a.py , b.py and keys.py , the latter contains nothing but keys as strings. a.pyb.pykeys.py ,后者只包含键作为字符串。

in a.py , I can do a.py ,我可以做

from keys import X

But in b.py pylint doesn't let me do that, I get 但是在b.py pylint中,我不这样做

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). 问题是Pylint看到文件包含在包中(因此from .keys import X的相对导入起作用)。 Trying to execute a.py directly is kind of "cheating" by trying to view the files as not in a package. 试图直接查看a.py有点“作弊”,因为尝试查看的文件不在软件包中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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