pyenv is using system python instead of virtual environment
Asked Answered
A

1

8

I've been using pyenv for a long time, without any troubles. I set up it properly and everything worked.

However, while I was trying to solve another problem, I run some line which ruined my pyenv instalation.

Now, when I activate any virtualenv, it tries to use system's python instead of pyenv's:

$ pyenv activate foo
(foo) $ which python 
/usr/bin/python
(foo) $ pip --version
pip 20.3.4 from /home/rodrigo/.local/lib/python2.7/site-packages/pip (python 2.7)

I'm not sure exactly which line was the one that ruined it, it may be the following: (foo) $ pip install --upgrade pip setuptools wheel from the foo environment (I run it when it still worked), but may be another.

I already checked ~/.bashrc file and it is ok; restarted the console and even changed to a different environment foo2 and the problem is still there...

I already checked similar questions like this or this, but those are related to miss-configurations which I already tested and are ok.

I'm using Ubuntu 18.04 LTS and pyenv 2.0.3-8-gad880754

UPDATE I re-installed pyenv but it still doesn't work

Anthologize answered 24/7, 2021 at 13:1 Comment(0)
C
7

I got it to work by changing ~/.zshrc:

Change

eval "$(pyenv init -)"

to

eval "$(pyenv init --path)"

and start a new shell.

Seems like this was a change that was introduced in 2.0.

Cubism answered 10/12, 2021 at 2:23 Comment(9)
awesome. This fixed the problem for meAchlorhydria
I keep getting Failed to activate virtualenv. Perhaps pyenv-virtualenv has not been loaded into your shell properly. Please restart current shell and try again. with this change.Juna
This error suggests that pyenv-virtualenv might not have been correctly loaded into your shell.Cubism
To resolve this, follow these stepsCubism
git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenvCubism
eval "$(pyenv virtualenv-init -)”Cubism
source ~/.zshrc # or use ~/.bashrc or appropriate file for your shellCubism
This solution works for me too, but as a side effect my prompt stopped showing name of the virtual env (which I previously set by pyenv local [virtual env. name] in that folder).Byzantium
By executing the command export PS1="(basename $VIRTUAL_ENV)$PS1", you can add the name of the currently activated virtual environment to your shell prompt.Cubism

© 2022 - 2024 — McMap. All rights reserved.