question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
galindrocommented, Feb 5, 2018

@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.

2reactions
DonJayamannecommented, Feb 21, 2018

@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).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Opening a Workspace causes python.pythonPath to be ignored
VS Code refuses to use the custom python.pythonPath I have specified in settings.json to run Python files through Microsoft's Python Extension.
Read more >
Using Python environments in VS Code
Configuring Python Environments in Visual Studio Code. ... Note: While it's possible to open a virtual environment folder as a workspace, doing so...
Read more >
How to Configure Eclipse for Python - Rose-Hulman
Enter http://pydev.org/updates in the Work with: field. After several seconds, two options should appear. Select the PyDev for Eclipse option. Do not select...
Read more >
Open, reopen, and close projects | PyCharm Documentation
Once you have opened the project, you should configure Python interpreter for ... that is not currently available, PyCharm shows a warning and...
Read more >
Efficient Way to Activate Conda in VSCode - Medium
If you have problem finding the conda virtual environment path, you can open a terminal with your target conda env activated, and then...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found