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.

pyenv + virtualenv not working - use pyenv activate for all

See original GitHub issue

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:

venv-vs-pyenv

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:

https://gist.github.com/fenchu/14b8fe5a0c24942f845a35106c7b176a

So please continue supporting it 😃

Thanks

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:38
  • Comments:24 (6 by maintainers)

github_iconTop GitHub Comments

25reactions
michaelwclarkcommented, Oct 3, 2019

Adding "python.terminal.activateEnvironment": false to my settings resolved this issue for me.

10reactions
taliesinbcommented, Oct 13, 2019

If VSCode can’t properly activate the python versions installed by pyenv, it should not pretend to support them!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pyenv doesn't change python version when activating ...
I installed pyenv-virtualenv using linuxbrew on my Ubuntu 16.04 VPS. I am using pyenv v1.2.16. Now when I do: pyenv install 3.8.1 pyenv...
Read more >
Failed to activate virtualenv with pyenv - Stack Overflow
Failed to activate virtualenv. Perhaps pyenv-virtualenv has not been loaded into your shell properly. Please restart current shell and try again ...
Read more >
Using pyenv and pyenv-virtualenv to install Python and create ...
How to use pyenv and pyenv-virtualenv to install a specific version of Python and create a virtual environment with that version on MacOS....
Read more >
yyuu/pyenv-virtualenv - Gitter
Failed to activate virtualenv. Perhaps pyenv-virtualenv has not been loaded into your shell properly. Please restart current shell and try again.
Read more >
Python: Version Management with Pyenv and Pyenv ... - Medium
To list all the available versions of python to be installed use the following command. pyenv ... Now let us see how to...
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