Reputation: 251
if someone could help me out with this issue it would be wonderful. I've currently tried everything over the last few days to get it to work with no success. I have used pyenv and the plugin virtualenv for about a month now with no issues. One day I woke up and found that I was unable to activate my virtualenv created by pyenv. Source bin/activate stopped working. I did everything from reinstalling pyenv all the way to reinstalling Kubuntu and trying again with no success. I can't tell whats wrong. I get no errors as you can see from the image below. To my understanding every time I activated a virtualenv it would show in my console before my name which it isn't doing anymore. I made sure to add "echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc" and all the other things required. All the other options available with pyenv still work fine, its only the activating of my virtualenv. Please help. Thanks
Upvotes: 1
Views: 3215
Reputation: 11
This took me a bit to understand too, especially because I managed my virtualenv's with virtualenvwrapper before. What helped is that I looked through the function and saw this:
if [[ "$(pyenv version-name)" == "system" ]]; then
pyenv deactivate || true
elif [[ "$VIRTUAL_ENV" != "$(pyenv prefix)" ]]; then
pyenv deactivate || true
pyenv activate 2>/dev/null || true
fi
What isn't covered is that when you create a virtualenv in pyenv, it shows up as a version. So when you do
pyenv versions
You get a list of your pythons -with- your virtual environments. To get this to work, its a combination of old functionality and new. You can do:
user@server [00:00:00] [~]
-> % cd Development/test
user@server [00:00:00] [~/Development/test]
-> % pyenv shell test
(test)user@server [00:00:00] [~/Development/test]
-> %
Or for automagic:
user@server [00:00:00] [~]
-> % cd Development/test
user@server [00:00:00] [~/Development/test]
-> % pyenv local test
(test)user@server [00:00:00] [~/Development/test]
-> %
This drops a .python-version file with the python version, which pyenv reads and uses as the virtualenv python.
Just remember to manage your virtualenv like python versions of pyenv and you should be able to keep things straight. For instance, to then deactivate automagically you just change directories. If you did pyenv shell, you will need to pyenv shell --unset or pyenv shell {another_version} to move virtualenv.
Hope this helps!
Upvotes: 1