I've seen many attempts at a fix for this question, but not have gotten it right for me. I love VSCode - it's good looking, lightweight, and fast. But I cannot understand how they made import statements so absolutely confusing. For context, I'm coming from Pycharm where everything just worked (after 10 minutes of waiting for the program to startup).
So, I have a folder structure that looks something like this:
How the interactions work currently:
- a.py and b.py can import with each other just fine with:
import (a|b).py - a.py and b.py can import with c.py and d.py just fine with:
from folder(1|2) import (c|d).py - c.py and d.py cannot import with a.py or d.py with:
from . import (a|b).py(which has been a recommended solution on other questions of a similar nature as this one) - c.py and d.py cannot import with each other with:
from .folder(1|2) import (c|d).py(I'm pretty sure the syntax is wrong here anyway)
My current settings.json is:
"python.pythonPath": "c:\\dev\\workspace-vscode\\Python\\Personal\\importTesting\\venv\\Scripts\\python.exe"
and my launch.json is:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"cwd": "${workspaceFolder}"
}
]}
I've seen solutions involving a .env file, but they never explain where to put the file. Also, what is the workspace folder? Where does that resolve to? Is it considered the root folder?
Something else to note is that the actual import statement that I'm using is: from Code.WordAnalysis.wordsAndLetters import word_count, which I understand will mean nothing to you unless you look at my code (which I've linked to below). But the goofy thing about that is that it works in Pycharm without breaking a sweat. This behavior makes me think it's some referencing issue - could be wrong.
The above import statement spits out this error:
Traceback (most recent call last): File "c:\dev\workspace-vscode\Python\WorkRelated\ITTechTalk\Code\PasswordStrengthCalculators\passwordstrengthreal.py", line 1, in <module> from Code.WordAnalysis.wordsAndLetters import word_count ModuleNotFoundError: No module named 'Code'
In case you want to look at my repository, it can be found here: https://github.com/TJMcButters/workspace-vscode/tree/master/Python/WorkRelated/ITTechTalk
Any help with this would be very much appreciated! It's driving me crazy.

__init__.pyfile to the folders so that you're able to import the modules from those folders.