Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pyenv local/global not working on catalina

I have a new MacBook with fresh installs of everything which I upgraded to macOS Catalina. I installed homebrew and then pyenv, and installed Python 3.8.0 using pyenv. All these things seemed to work properly.

However, neither pyenv local nor pyenv global seem to take effect. Here are all the details of what I'm seeing:

thewizard@Special-MacBook-Pro ~ % pyenv versions
   system
 * 3.8.0 (set by /Usersthewizard/.python-version)
thewizard@Special-MacBook-Pro ~ % python --version
 Python 2.7.16
thewizard@Special-MacBook-Pro ~ % pyenv global 3.8.0
thewizard@Special-MacBook-Pro ~ % python --version
 Python 2.7.16
thewizard@Special-MacBook-Pro ~ % pyenv local 3.8.0
thewizard@Special-MacBook-Pro ~ % python --version
 Python 2.7.16
thewizard@Special-MacBook-Pro ~ % echo $PATH
 /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/thewizard/.pyenv/bin
thewizard@Special-MacBook-Pro ~ % cat ~/.zshenv
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
if command -v pyenv 1>/dev/null 2>&1; then
   eval "$(pyenv init -)"
fi

BTW there is no /bin in my .pyenv, I only added those commands per some other instructions but I'm planning to remove it because I think it is wrong:

thewizard@Special-MacBook-Pro ~ % ls -al ~/.pyenv 
total 8
drwxr-xr-x   5 thewizard  staff  160 Nov  2 15:03 .
drwxr-xr-x+ 22 thewizard  staff  704 Nov  2 15:36 ..
drwxr-xr-x  22 thewizard  staff  704 Nov  2 15:03 shims
-rw-r--r--   1 thewizard  staff    6 Nov  2 15:36 version
drwxr-xr-x   3 thewizard  staff   96 Nov  2 15:01 versions

It's worth noting that Catalina moved to zsh from bash, not sure if that's relevant here.

like image 312
Stephen Avatar asked Nov 02 '19 19:11

Stephen


2 Answers

If you're using pyenv with pipenv and encountering the same issue, you can add the following lines to your .zshrc or .zprofile file:

export PYENV_ROOT="$HOME/.pyenv/shims"
export PATH="$PYENV_ROOT:$PATH"
export PIPENV_PYTHON="$PYENV_ROOT/python"

Referencing pyenv's /shims folder helps to keep it more general and to allow you to easily switch between different Python versions, should you have more than one installed.

pipenv will then always reference the version of Python that is currently set as global by pyenv.

like image 75
martin-martin Avatar answered Oct 12 '22 11:10

martin-martin


I added the following to my ~/.zprofile and got it working.

export PYENV_ROOT="$HOME/.pyenv/versions/3.7.3"
export PATH="$PYENV_ROOT/bin:$PATH"
like image 28
Malte Avatar answered Oct 12 '22 11:10

Malte