I am trying to use Visual Studio Code with virtual environment. In the Launch JSON I specify the nosetests launch like this:
{
"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 launch the environment variables do not get picked up. I've tried setting up the python path in workspace settings:
"python.pythonPath": "${workspaceRoot}/env/dev/bin/python"
but it doesn't seem to set the right environment. There needs to be something that' the equivalent of source activate. Has anyone figured it out?
A virtual environment is a folder that contains a copy (or symlink) of a specific interpreter.
Create a virtual environmentUnder Install packages from file, provide the path to a requirements. txt file if desired. Activates the new environment in the selected project after the environment is created. Automatically sets and activates the virtual environment in any new projects created in Visual Studio.
@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 that's how you need to configure it in launch.json.
With the next version of VS Code you will no longer have to do this, i.e. you won't have to configure this same setting in two files.
More details on configuring the path for debugging can be found here: https://github.com/DonJayamanne/pythonVSCode/wiki/Python-Path-and-Version#python-version-used-for-debugging
You need to set up the path for your virtual environments in your workspace settings file: https://code.visualstudio.com/docs/python/environments
Save your workspace then open <workspace_name>.code-workspace
file and add your virtual environment folder to the settings:
{
"folders": [
{
"path": "<path-to-your-workspace>"
}
],
"settings": {
"python.venvPath": "<path-to-your-virtual-env-folder>"
}
}
After that open command palette (CMD/CTRL + SHIFT + P) and type select interpreter
. Then choose the one from the desired virtual environment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With