Reputation: 1719
I am using vscode on my desktop and laptop and each machine would generate a random folder name with a hash for the virtual environment path when creating the virtual environment using poetry. In order to use the same launch.json file in my project for both computers, I'd like to reference an environment variable instead of hard coding the virtual environment path names. I've tried the below but vscode is stating "The Python path in your debug configuration is invalid." How can I reference the environment variable for the "python" path?
my ~/.zshrc
:
export PROJ_VENV=$HOME/.cache/pypoetry/virtualenvs/myproj-NMmw6p6o-py3.12
my launch.json
:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Django",
"type": "python",
"python": "${env:PROJ_VENV}/bin/python",
"request": "launch",
"program": "${workspaceFolder}/src/manage.py",
"args": [
"runserver",
],
"django": true
}
]
}
Upvotes: 3
Views: 455
Reputation: 1719
As of vscode 1.85, specifying "python": "${env:PROJ_VENV}/bin/python"
in launch.json
will not work. As a workaround, you can remove "python" from launch.json
and set "python.defaultInterpreterPath": "${env:PROJ_VENV}/bin/python"
in settings.json
. You can then select "Use Python from python.defaultInterpreterPath" when selecting your python interpreter.
Upvotes: 1