[英]Python peek definition works in vscode, but pylint complains about being unable to import
I want to test some python files in a project before installing them. 我想在安装它们之前在项目中测试一些python文件。 For this I entered the folder to be installed in my vscode workspace settings as follows: 为此我输入了要在我的vscode工作区设置中安装的文件夹,如下所示:
"python.autoComplete.extraPaths": [
"${workspaceRoot}/lib_python/release"
]
Now I have a test file in my workspace that imports from the above mentioned folder. 现在我的工作区中有一个测试文件,可以从上面提到的文件夹中导入。 Suggestions work fine, it also gives me definitions while hovering with the mouse over a class name from the imported file. 建议工作正常,它还为我提供了定义,同时将鼠标悬停在导入文件的类名上。 However, half my code is underlined in red, because pylint says it does not know the definitions and cannot import. 但是,我的一半代码用红色加下划线,因为pylint说它不知道定义而无法导入。
Question: Is there a way to also make whatever part of the python plugin by Don Jayamanne
is responsible for the red underlining find the additional import folders? 问题:有没有办法让Don Jayamanne
的python插件的任何部分负责红色下划线找到额外的导入文件夹?
So what worked for me now is to set additional paths in a .env
file in the project's root folder. 那么现在对我.env
是在项目的根文件夹中的.env
文件中设置其他路径。 This file will be read by the python extension of vscode. 该文件将由vscode的python扩展读取。
Example: 例:
PYTHONPATH=./lib_python/release
In User Settings -> Extensions be sure python
command is the right one. 在用户设置 - >扩展中,确保python
命令是正确的。 On my Mac, python
refers to Python 2.x, however python3
refers to Python 3.X. 在我的Mac上, python
指的是Python 2.x,但是python3
指的是Python 3.X. I simply changed VSCode's python
command to python3
and this resolved my issue. 我只是将VSCode的python
命令更改为python3
,这解决了我的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.