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?
UPDATE. As a temporary solution I have just suppressed the disturbing error message in VS Code. It is explained here why to do this in the right way you should go to Workspace Settings, find 'Pylint Args' and add three items:
--disable=all
--enable=F,E,unreachable,duplicate-key,unnecessary-semicolon,global-variable-not-assigned,unused-variable,binary-op-exception,bad-format-string,anomalous-backslash-in-string,bad-open-mode
--disable=F0401
After this imports that are really wrong are still marked by another color in VS Code color scheme so I can see my mistakes.