Repository navigation
Description
Environment data
- VS Code version: 1.30.2
- Extension version (available under the Extensions sidebar): vscode-python 2018.12.1
- OS and version: ubuntu 16.04LTS
- Python version (& distribution if applicable, e.g. Anaconda): any pypy,cpython
- Type of virtual environment used (N/A | venv | virtualenv | conda | ...): pyenv
- Relevant/affected Python packages and their versions: None
Expected behaviour
When choosing python interpreter it lists all versions under ~/.pyenv correctly (see png below), but
the ones created with pyenv+virtualenv like pyenv virtualenv 3.7.2 mycoolapp which creates a venv environment under pyenv using python 3.7.2 with the name mycoolapp.
This should be activated with:
pyenv activate mycoolapp
The ones listed with venv VSC does:
$ source /home/mortenb/.pyenv/versions/mycoolapp/bin/activate
The ones listed with pyenv (the ones created with pyenv install 3.7.2, that downloads, compile and install the specified python version):
$pyenv shell 3.7.2
this works for base versions not for pyenv+virtualenv, but I recommend using pyenv activate for all
$ pyenv help activate
Usage: pyenv activate <virtualenv>
pyenv activate --unset
Activate a Python virtualenv environment in current shell.
This acts almost as same as `pyenv shell`, but this invokes the `activate`
script in your shell.
<virtualenv> should be a string matching a Python version known to pyenv.
Example loading flask on python 3.6.2:
VSC does when opening a terminal:
$ source /home/mortenb/.pyenv/versions/flask/bin/activate
$ which python
/home/mortenb/.pyenv/shims/python
$ python --version
Python 3.7.0
It is wrong version, if it had done this it would have been correct:
$ pyenv activate flask
pyenv-virtualenv: prompt changing will be removed from future release. configure `export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
(flask) mortenb@mortenb-home1:/dist/sensio/unity-selenium$ which python
/home/mortenb/.pyenv/shims/python
(flask) mortenb@mortenb-home1:/dist/sensio/unity-selenium$ python --version
Python 3.6.2
Pyenv is a terrific technology, we manage full python versioning control within docker containers by a single build parameter. This container tagged with version number we use as base container for all python projects within the company, it makes regression testing and upgrading a oneliner in jenkins:
So please continue supporting it :-)
Thanks

Activity
znd4 commentedon Apr 29, 2019
Would this fix be implemented in
vscode-python, or would it happen in the python language server?I'd love to try to figure out how to get this to work, if no-one's already working on it. (
pyenvis pretty awesome, and it would be great if I could use it with vscode)clbarnes commentedon May 22, 2019
It's surprising that the python extension explicitly looks for python versions installed by pyenv, but then can't activate them.
michaelwclark commentedon Oct 3, 2019
Adding
"python.terminal.activateEnvironment": falseto my settings resolved this issue for me.31 remaining items
andreamah commentedon Sep 27, 2023
Kartik Raj (@karrtikr) Can you provide minimal steps to verify this?
karrtikr commentedon Sep 27, 2023
Verification steps:
Python: Select Interpreter, give it a couple seconds to activate:Make sure it points to the path of the selected interpreter.
andreamah commentedon Sep 27, 2023
I don't think it enables the env correctly? This is when I create a new terminal and run the command
karrtikr commentedon Sep 27, 2023
I don't think you're opted into experiement, can you make sure? Note it requires a reload.
andreamah commentedon Sep 27, 2023
Seems that, when I added the setting to user settings, it didn't register. Moved it to the remote settings and it worked 👍
jasonbrancazio commentedon Oct 2, 2023
I like the new auto-activation, but now as you've noted the deactivate command is broken. It took me a while to figure out why:
#22037
Adding a huge chunk of bash as suggested in issue 22037 to my ~/.bashrc is an inconvenient way to work around this.
karrtikr commentedon Oct 2, 2023
While we understand that the current workaround involving ~/.bashrc can be inconvenient, but unfortunately we're limited by VS Code.
FWIWI we're actively working on a notification system to help users discover this solution more easily #22121, which can mitigate at least some part of the issue.
karrtikr commentedon Oct 3, 2023
Jason Brancazio (@jasonbrancazio) Would it work if we were to provide a Python command to open a new terminal which is deactivated? We're trying to understand why "deactivate" command is used, and if there are any alternatives we could provide.
jasonbrancazio commentedon Oct 4, 2023
The preference setting to disable auto-activation was sufficient for me.
I activate and deactivate virtual environments all the time. I often deactivate them if I want to delete them from disk and recreate them. I also might create two virtual environments, each with different versions of libraries installed, switch between them by activating and deactivating, and test code in each environment.