I am unable to get pyenv-virtualenvwrapper plugin to work on my Ubuntu host. I have pyenv, virtualenvwrapper, and pyenv-virtualenvwrapper plugin installed (and in correct plugin directory).
- I tried running
pyenv local 3.9.17, thenpython --versionshows 3.9.17 - I then try to run
mkvirtualenv projectand thenpython --versionshows wrong version
I also tried pyenv shell 3.9.17 before creating the env, same results. Even pyenv global 3.9.17 wont work in my vitual env. Note: I have been source ~/.bashrc every time I make a change in it.
The github for pyenv-virtualenvwrapper says this:
Using pyenv virtualenvwrapper To setup a virtualenvwrapper into your shell, just run pyenv virtualenvwrapper. For example,
$ pyenv virtualenvwrapper or, if you favor virtualenvwrapper_lazy.sh,
$ pyenv virtualenvwrapper_lazy
Tried that, same results. Here is the bottom of my ~/.bashrc
# Python3 virtualenvwrapper
#export WORKON_HOME=$HOME/.virtualenvs
#export PROJECT_HOME=$HOME/projects
#source /usr/local/bin/virtualenvwrapper.sh
#source $HOME/.local/bin/virtualenvwrapper.sh
#export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python
#pyenv
#export PATH="$PATH:$HOME/.pyenv/libexec"
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
#pyenv-virtualenvwrapper plugin
export PYENV_VIRTUALENVWRAPPER_PREFER_PYVENV="true"
#pyenv virtualenvwrapper_lazy
pyenv virtualenvwrapper
# Rust stuff
. "$HOME/.cargo/env"
export PATH="$HOME/.cargo/bin:$PATH"
Why wont this work? Ideally I want to create the .python-version file in my repo, and then any time I workon project then it will use the correct python version.
Ok I figured out how to get this to work. I found this github markdown file that details how to properly set this up. No where else were these instructions clear to me. Here they are below, I adjusted a few things, naming conventions, and set up env configurations in the
~/.bashrcinstead of~/.bash_profile.~/.bashrcto remove any settings referencing these.Install [pyenv][] using [pyenv-installer][]:
Activate pyenv for Terminal:
Exit and restart Terminal.
Install Python:
Exit and restart Terminal.
Verify that you are now using the version of Python you just installed:
Install [pyenv-virtualenvwrapper][]:
Activate pyenv-virtualenvwrapper for Terminal:
Exit and restart Terminal.
Now create the virtualenvwrapper using pyenv:
Now when I do
workonit shows the correct version and the connects me to the specific directory (git repo directory) that the project is in. Very useful!Not sure if
pyenv global <some version> systemwas needed. I was able to set this back to the original python version the system was using and it did not affect the pyenv-virtualenvwrapper env I set up.NOTE: If you want to change pyenv versions for an active project, you cant, you have to create a new one with the specific version you want.