I currently run code for a project I’m working on with python using the following example command line in my workspace folder for the project.
python -m testing.test_file
This is because my project files are setup something like this;
project_folder
├───src
| ├───__init__.py
│ ├───main_class.py
| └───utils.py
|
└───testing
├───__init__.py
├───test_file.py
└───main.py
and src file contains various python files that are imported in main.py and test_file.py for example.
I have tried modifying the vscode launch.json file by changing program to ${workspacefold} and adding the args "-m testing.test_file" but it always either can’t find the file or runs it can find the imports because it is running from wrong directory.
While it is fine running it using the simple command line I use currently, I wanted to try to get it working with the debugger in vscode etc rather than print debuging.
2
Answers
If anyone was curious, the solution I ended up using was a
launch.json
environment file which looked like this;You could try to add a
.env
file including thePYTHONPATH
under your workspace.Then add
"python.envFile": "${workspaceFolder}/.env",
to yoursettings.json
.