Visual Studio Code and virtualenv

I am trying to use Visual Studio Code with a virtual environment. In Launch JSON, I indicate that the sockets run as follows:

{ "name": "nosetests", "type": "python", "request": "launch", "stopOnEntry": true, "program": "${workspaceRoot}/env/dev/bin/nosetests", "args": [ "--nocapture", "tests" ], "externalConsole": false, "debugOptions": [ "WaitOnAbnormalExit", "WaitOnNormalExit" ] }, 

However, when I run the environment variables, they are not collected. I tried setting python path in workspace settings:

 "python.pythonPath": "${workspaceRoot}/env/dev/bin/python" 

but it does not seem to establish the correct environment. There must be something that "the source equivalent is activated. Has anyone understood this?"

+7
python visual-studio-code nose
source share
2 answers

@mikebz you need to configure the path to the python executable as follows:
"pythonPath":"${workspaceRoot}/env/dev/bin/python"

The path may not be 100% accurate (please double check it), but this is how you need to configure it in launch.json.
In the next version of VS Code, you no longer have to do this, i.e. You do not have to configure the same parameter in two files.

More information on setting the path for debugging can be found here: https://github.com/DonJayamanne/pythonVSCode/wiki/Python-Path-and-Version#python-version-used-for-debugging

+8
source share

As an article appeared in 2018.03 on how to add virtualenv to your python path list for a specific workspace: https://code.visualstudio.com/docs/python/environments

All you have to do is File->Save workspace as.. and then add virtualenv to your workspace settings:

 { "folders": [ { "path": "." } ], "settings": { "python.pythonPath": "${workspaceFolder}/.venv/bin/python" } } 
+1
source share

All Articles