vscode-python: python.pythonPath doesn't work properly in workspace with multiple python projects

Environment data

VS Code version: 1.19.3 Python Extension version: 2018.1.0 Python Version: 3.6.4 OS and version: Ubuntu 16.04

Actual behavior

In a workspace with multiple projects associated to multiple virtual environments, the association with virtual environments doesn’t work anymore. VSCode Python keep using the virtual environment defined in the first project of the workspace. If I open the single projects, the association with virtual environment works as expected.

Expected behavior

Correct association to a proper virtual environment for every project in a workspace.

Steps to reproduce:

  • Add at least two projects in a workspace
  • Configure a different virtual environment for every project using python.pythonPath
  • Save the workspace
  • Reload the window and check the virtual environment loaded by VSCode for each project

Logs

Output from Python output panel

Output from Console window (Help->Developer Tools menu)

/usr/share/code/resources/app/out/vs/workbench/workbench.main.js:249 [Extension Host] Python Extension: Failed to get conda info from conda null
t.log @ /usr/share/code/resources/app/out/vs/workbench/workbench.main.js:249
/usr/share/code/resources/app/out/vs/workbench/workbench.main.js:249 [Extension Host] (node:26467) DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
t.log @ /usr/share/code/resources/app/out/vs/workbench/workbench.main.js:249

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 2
  • Comments: 28

Commits related to this issue

Most upvoted comments

@DonJayamanne I’ve seen the same problem here, in my env. I’ll try to clarify @pferretti explanation for you through a simple example:

  1. Create two python virtualenvs. You could use virtualenvwrapper for this. P.S.: I’m using python 3.6, but you could use 2.7. This error isn’t tied to the python version.
mkvirtualenv -p /usr/bin/python3.6 project_1
mkvirtualenv -p /usr/bin/python3.6 project_2
  1. Create .vscode with a settings.json file on each virtualenv folder, like bellow:
settings.json from project_1
{
    "python.pythonPath": "/<your_root_folder>/project_1/bin/python"
}
settings.json from project_2
{
    "python.pythonPath": "/<your_root_folder>/project_2/bin/python"
}
  1. Create a simple python script on each virtualenv, like bellow:
main.py from project_1
print("Hello World!")
main.py from project_2
print("Hello World!")
  1. Check if the root folder content of your workspace is like bellow:
Folder contents:
project_1
├── bin
│   ├── activate
│   ├── activate.csh
│   ├── activate.fish
│   ├── activate_this.py
│   ├── easy_install
│   ├── easy_install-3.6
│   ├── epylint
│   ├── get_env_details
│   ├── isort
│   ├── pip
│   ├── pip3
│   ├── pip3.6
│   ├── postactivate
│   ├── postdeactivate
│   ├── preactivate
│   ├── predeactivate
│   ├── pylint
│   ├── pyreverse
│   ├── python -> python3.6
│   ├── python3 -> python3.6
│   ├── python3.6
│   ├── python-config
│   ├── symilar
│   └── wheel
├── include
│   └── python3.6m -> /usr/include/python3.6m
├── lib
│   └── python3.6
├── main.py
├── pip-selfcheck.json
└── .vscode
    └── settings.json
project_2
├── bin
│   ├── activate
│   ├── activate.csh
│   ├── activate.fish
│   ├── activate_this.py
│   ├── easy_install
│   ├── easy_install-3.6
│   ├── epylint
│   ├── get_env_details
│   ├── isort
│   ├── pip
│   ├── pip3
│   ├── pip3.6
│   ├── postactivate
│   ├── postdeactivate
│   ├── preactivate
│   ├── predeactivate
│   ├── pylint
│   ├── pyreverse
│   ├── python -> python3.6
│   ├── python3 -> python3.6
│   ├── python3.6
│   ├── python-config
│   ├── symilar
│   └── wheel
├── include
│   └── python3.6m -> /usr/include/python3.6m
├── lib
│   └── python3.6
├── main.py
├── pip-selfcheck.json
└── .vscode
    └── settings.json
  1. Now, open vscode and add those two folder projects in a new workspace, begging with project_1. See the print bellow:

image

6 - Open the project_1/main.py file and check the python path in the botton of the screen. You must just stay with the mouse pointer on it and a pop-up will open telling you the python path:

image

As you can see above, it points to the python interpreter installed on project_1 folder. This is fine.

7 - Now open the project_2/main.py and make the same steps above:

image

See that the python interpreter used by this folder is the same as project_1, instead of project_2. Even if I try to click on that menu and try to change the python interpreter of project_2 folder, it not works, because the menu always point to project_1 folder. Check the bellow prints:

image

image

I hope that I was clear enough.

@lig @galindro @jkehler @Tantalus13A98B5F The issue has been fixed and the fix will be delivered along with the next version (end of the month). For the moment, please feel free to download the latest Insiders Build of the extension (its contains all fixes and current dev work to be released in the next version).

@lig I believe I know what’s happened, our CI tests are failing hence the extension isn’t getting built. Please test this build of the extension.

Apologies for this issue. Hopefully we’ll have the CI tests resolved tomorrow (we’ve already got a PR lined up to resolve that)

Same here. Reproduces in 1.20. Makes vscode python extension almost unusable and results in false errors from all over the workspace. I had 9 folders in the same workspace and now I’m forced to remove and readd folders continuously to be able to use the extension.

Thanks @galindro , a perfect explanation 😃