简体   繁体   中英

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. 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. However this form of statement raises pylint import error 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' .

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.

Is it possible to change configurations in PyCharm and/or VS Code to make any form of import statement acceptable for both of them?

Maybe you can use the sys.path.append() method.

import sys
sys.path.append("put_your_path_here")

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