Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code keeps changing my "python.pythonPath"

I have been using settings.json for a while now to share some project settings accross my different machines (which happen to be Linux, macOS and Windows). One of the settings I use is "python.pythonPath", which points to a interpreter inside the .venv created by the Poetry tool. Since Windows and linux-based operating system paths differ for virtualenvs, I need to set an environment variable with the proper path, e.g.: CLAYMEMOIRS_INTERPRETER.

I started noticing a problem where, whenever I launch visual studio code, my:

{ 
    ...
    "python.pythonPath" : "${env:CLAYMEMOIRS_INTERPRETER}" 
}

Gets automatically replaced with:

{ 
    ...
    "python.pythonPath" : "c:\\GitHub\\claymemoirs\\.venv\\Scripts\\python.exe"
}

Which is the value of my environment variable. Anyone knows how I can prevent this behaviour? I did not do any updates or changed any plugins.

like image 683
Francisco Barros Avatar asked Aug 15 '26 21:08

Francisco Barros


1 Answers

The problem persists, but newer releases indicate python.pythonPath is being deprecated in favor of python.defaultInterpreterPath. See here.

One of the reasons for deprecation is the questioned problem.

With the new python.defaultInterpreterPath set in the workspace settings file (.vscode/settings.json) you can use environment variables to set the project .venv path in a OS independant manner "${workspaceFolder}${env:CLAYMEMOIRS_INTERPRETER}". When someone from the team loads opens the project's folder in VSCode, the interpreter will appear on the selectlist, allowing developers to select the project interpreter without messing with other people's interpreters and, without changing the workspace path.

like image 135
Francisco Barros Avatar answered Aug 18 '26 12:08

Francisco Barros