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.

venv not working for custom location (after vscode restart)

See original GitHub issue

Environment data

  • VS Code version: 1.50.1
  • Extension version (available under the Extensions sidebar): v2020.10.332292344
  • OS and version: Win7 x64
  • Python version (& distribution if applicable, e.g. Anaconda): 3.8
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): venv
  • Relevant/affected Python packages and their versions: XXX
  • Relevant/affected Python-related VS Code extensions and their versions: XXX
  • Value of the python.languageServer setting: XXX

Expected behaviour

After pointing ‘Python: Select Interpreter’ to a custom location(e.g. ‘C:\VENVs\venv1’), the virtual environment is used for the current workspace, which is indicated in the status bar. Closing VSCode and reopening it, should not break this behavior.

Actual behaviour

The venv in the custom location is used correctly the first time it is added to VSCode. After VSCode is closed and reopened again, the venv is non functional inside VSCode. It is correctly configured in the workspace’s settings.json. The statusbar shows the correct path while hoovering over the current interpreter, but the status bar caption is missing the indicator that this is a venv. Opening an integrated terminal shows the (venv1) prefix, but the venv is not loaded correctly(e.g. python command is missing, because path to venv executable is not loaded). Furthermore installed packages are missing, which clearly indicates that the wrong interpreter is being used.

After making an venv unusable ‘buggy’(by adding it, closing and reopening VSCode) it will show this behavior even for a different workspace, where it hasn’t been selected previously at all.

Update regarding behavior

At first it seemed that the configured venv is also not used at all, but I noticed that this was actually my mistake(I wasn’t aware that moving a venv breaks its function in general, because absolute paths are hardcoded in its internal scripts).

Therefore the update: The configured interpreter seems to be used correctly by VSCode, but after closing and reopening VSCode, the sufix in the status bar, e.g.: ‘(venv: myvenv)’ is missing. This has been obeserved not only for the broken venv, but also for new created venvs.

Steps to reproduce:

  1. create a new workspace
  2. create and select a venv in a custom location
  3. verify that venv is used correctly by VSCode
  4. close and reopen VSCode
  5. observe broken behavior of previously selected workspace

Notes

I currently don’t have the ressources to analyze this in detail - what I have seen so far:

After adding the python interpreter for the first time it gets added to the SQLite database in the configuration folder User\globalStorage\state.vscdb under the key ms-python.python. I haven’t tried to tinker with the entries manually, but it is probably related to the existence of this entry?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:8

github_iconTop GitHub Comments

1reaction
karrtikrcommented, Nov 11, 2020

@Silun The issue you face is dup of Closed as dup of https://github.com/microsoft/vscode-python/issues/14645

1reaction
karrtikrcommented, Nov 11, 2020

@Silun I think your issue is different from the one @dmi-github stated, but it’s dup of the other issue I’m investigating, would greatly appreciate your help there. Can you please fill the issue template and link more details in a comment there: https://github.com/microsoft/vscode-python/issues/14645

I’m especially interested in the last edit comment your left about “double pythonpath”, please elaborate and leave a comment there, thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Virtual Environment not activated after restarting VScode
venv in my project directory. If I press CTRL+SHIFT+P and select my environment, then open a new Terminal session, the new environment is ......
Read more >
Using Python environments in VS Code
From within VS Code, you can create non-global environments, using virtual environments or Anaconda, by opening the Command Palette (Ctrl+Shift+P), start typing ...
Read more >
Using Python Virtual Environment in VSCode - Tech Inscribed
1. Update Venv Path Settings in VSCode ... Restart VSCode and click on the interpreter version on the left-bottom corner. ... Now, you...
Read more >
Advanced Visual Studio Code for Python Developers
In this tutorial, you'll learn how you can configure, extend, and optimize Visual Studio Code for a more effective and productive Python development ......
Read more >
Autocomplete | Python in Visual Studio Code
1. Intellisense/Autocompletion not working for custom modules · Cause: The path to the python executable is incorrect. Solution: Configure the path to the...
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