[英]Is there a way to make pylint import configurations compatible in PyCharm and VS Code?
While I run and debug my project in PyCharm, currently using Python 3.10, I also often prefer to edit my code in VS Code.当我在 PyCharm(目前使用 Python 3.10)中运行和调试我的项目时,我也经常更喜欢在 VS Code 中编辑我的代码。 The file structure of my project looks like:
我的项目的文件结构如下:
my_project_folder
├─ subfolder_1
├─ subfolder_2
├─ …
├─ __init__.py
└─ application.py
Import statements in my code look like我的代码中的导入语句看起来像
from subfolder_1 import func1, func2
and it works perfectly in PyCharm.它在 PyCharm 中完美运行。 However this form of statement raises pylint import error
Unable to import 'subfolder_1'
in VS Code.但是,这种形式的语句会引发 pylint 导入错误
Unable to import 'subfolder_1'
in VS Code。
At the same time if I change an import statement like同时,如果我更改导入语句,例如
from my_project_folder.subfolder_1 import func1, func2
it raises no errors in VS Code, but I can not run the project in PyCharm due to the error Unresolved reference 'my_project_folder'
.它在 VS Code 中没有引发任何错误,但由于错误
Unresolved reference 'my_project_folder'
,我无法在 PyCharm 中运行该项目。
As for now I am not going to work on any new python project, so I did make no special configuration changes (like adding virtual environment, etc.) either in PyCharm or in VS Code.至于现在我不打算在任何新的 python 项目上工作,所以我没有在 PyCharm 或 VS Code 中进行任何特殊的配置更改(如添加虚拟环境等)。
Is it possible to change configurations in PyCharm and/or VS Code to make any form of import statement acceptable for both of them?是否可以更改 PyCharm 和/或 VS Code 中的配置以使任何形式的导入语句都可以接受?
Maybe you can use the sys.path.append()
method.也许您可以使用
sys.path.append()
方法。
import sys
sys.path.append("put_your_path_here")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.