简体   繁体   English

vscode python linting的PYTHONPATH命名限制

[英]PYTHONPATH naming restrictions for vscode python linting

I am using vscode with python and other languages in a single project. 我在单个项目中将vscode与python和其他语言一起使用。 The directory structure is like this: 目录结构如下:

- base
 - python
  - foo
    foo.py
  - bar
    bar.py
 - bin
 - etc

I am getting 'python(unresolved import)' warnings in vscode when importing modules such as 'foo'. 导入模块(例如“ foo”)时,我在vscode中收到“ python(无法解析的导入)”警告。

I used a solution provided by Tomasz C. here: Pylint "unresolved import" error in visual studio code 我在这里使用了Tomasz C.提供的解决方案: Visual Studio代码中的Pylint“ unresolved import”错误

In my case I have a .env file with 就我而言,我有一个.env文件,

PYTHONPATH=python/

This does not work! 这行不通!

I have renamed this portion of my directory structure to anything else (like PYTHONPATH=python2/) and it does work. 我已经将目录结构的这一部分重命名为其他任何名称(例如PYTHONPATH = python2 /),并且它确实起作用。

I have also tried multiple linters with no change. 我还尝试了多个Linter,但没有进行任何更改。

I am not in control of the naming of these directories. 我无法控制这些目录的命名。 Is there some way I can get linting with vscode to work with existing directory structure? 有什么办法可以使vscode与现有目录结构一起使用?

PYTHONPATH should point to a valid python executable instance, it should be the one being used by your environment, so you have to give it the full absolute path, not a relative one. PYTHONPATH应该指向一个有效的python可执行实例,它应该是您的环境正在使用的实例,因此您必须为其提供完整的绝对路径,而不是相对路径。 example: /home/user/environment/bin/python , change it according to your setup. 例如: /home/user/environment/bin/python ,根据您的设置进行更改。

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

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