I have read Use a python package in the same project folder in visual studio code but it still doesn't work. Environment: Windows 10, Python 3.10.1 virtual environment, VSCODE 1.60.2 VS Default Interpreter: C:\data\tools\python310\venv\Scripts\python.exe I have a python 3.9 installed, and installed all the modules for the 3.9 to C:\data\tools\Python. I have assigned the PYTHONPATH variable to at the system level for that 3.9. This is my project file structure:
.
│ .env
├───.vscode
│ launch.json
│ settings.json
├───api
│ adhoc.py
│ __init__.py
├───config
│ config.json
├───test
│ │ testUtil.py
├───utils
│ │ dbutil.py
│ │ fileutil.py
│ │ util.py
│ │ __init__.py
Here's how I start my VSCODE from Windows Command Line:
set PYTHONPATH=
cd C:\data\tools\python310\venv\Scripts
activate
"C:\Program Files\Microsoft VS Code\Code.exe"
Here's my .env:
PYTHONPATH=.\utils:${PYTHONPATH}
Here's my settings.json:
{
"python.testing.unittestArgs": [
"-v",
"-s",
"./test",
"-p",
"*test*.py"
],
"python.envFile":${workspaceFolder}/.env
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true,
"python.linting.enabled": true
}
Here's my adhoc.py:
from utils.dbutil import readSQL, run_select
from utils.util import get_time_file, get_path
- I can run all the tests successfully from VSCODE->Discover Test etc
- I can run the adhoc.py successfully from pycharm
- When I right click adhoc.py in VSCODE->Run Python File from Terminal, the error message is as below:
ModuleNotFoundError: No module named 'utils'
Any idea please?