pyenv local/global not working on catalina
Asked Answered
M

7

18

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.

Mahdi answered 2/11, 2019 at 19:46 Comment(7)
When looking at your $PATH, it seems the system directories /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin all have precedence over your pyenv directory. If your system has Python 2.7 in /usr/local/bin, running python will use Python 2.7 in that case. Can you set the path manually with export PATH="/Users/thewizard/.pyenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" and re-try?Polyzoarium
I suspect you have another dotenv file being sourced after .zshenv, which overwrites your path. Does your .zshrc overwrite the $PATH?Polyzoarium
@Polyzoarium yes I can do that and you might be on to something - but as I mentioned there is no /bin in my .pyenv, so I think it might be fruitless. The only bin I see is in ~/.pyenv/versions/3.8.0/ As for .zshrc that file doesn't exist. I don't have other zsh files in my home directory, and in fact .zshenv is a file I made myself.Mahdi
I'm not sure it would be in the spirit of StackOverflow, but would you be open to just re-installing pyenv using the official pyenv installer rather than Brew? I wrote a tutorial a while ago with all the steps.Polyzoarium
Thanks, I will try that!Mahdi
I was able to get it working just by adding the commands in your tutorial to my .zshrc file. Incidentally one of the commands (with virtualenv-init in it) gives an error to me, but things seem to work regardless. Thanks for the tip!Mahdi
I ran into the same issue today. Like Stephen said there is no bin in .pyenv. Putting /Users/<username>/.pyenv/versions/3.7.3/bin in first place in the PATH in .zprofile (the new -bash_profile) worked. However, I am also trying to figure out why this is happening. There is no .zshrc in my home folder.Northing
C
29

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.

Centare answered 25/1, 2020 at 14:6 Comment(0)
N
7

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"
Northing answered 17/11, 2019 at 4:1 Comment(2)
And below that... . $PYENV_ROOT/bin/virtualenvwrapper.sh instead of . ~/.pyenv/versions/3.7.3/bin/virtualenvwrapper.shNorthing
this helped me, thx. it can be made more general like so: https://mcmap.net/q/655401/-pyenv-local-global-not-working-on-catalinaCentare
O
1

Also check that venv is not activated.

It may be activated automatically in your IDE console.

Opulent answered 3/8, 2023 at 13:58 Comment(1)
In VS Code, my issue was $PYENV_VERSION was set and therefore pyenv local ... didn't work. Setting "python.terminal.activateEnvironment": false, in the settings.json fixed it.Inactivate
A
0

catalina (and OS X in general) uses /etc/zprofile to set the $PATH in advance of what you're specifying within the local dotfiles.

it uses the path_helper utility to specify the $PATH and i suspect this is overriding the shim injection in your local dotfiles. you can comment out the following lines in /etc/zprofile. this will get overridden in subsequent OS updates.

# if [ -x /usr/libexec/path_helper ]; then
#   eval `/usr/libexec/path_helper -s`
# fi

alternately, and less intrusively, you can unset the GLOBAL_RCS option (add unsetopt GLOBAL_RCS) in your personal .zshenv file which will allow you to suppress sourcing all of the system default RC files for zsh and allow the pyenv shims to operate as intended.

Alphonsealphonsine answered 16/12, 2019 at 14:54 Comment(0)
S
0

Check if exist any symbolic links on your account root

ls -al .pyenv/versions/x.x.x/bin

if you don't have symlink files

unset CLICOLOR
unset CLICOLOR_FORCE
unset LSCOLORS
unalias ls

and try python install again with pyenv

Shoemake answered 2/4, 2020 at 8:26 Comment(0)
I
0

I think the issue is due to the default HD partitions that might be causing confusion. "With macOS Catalina, you can no longer store files or data in the read-only system volume, nor can you write to the "root" directory ( / ) from the command line, such as with Terminal" (https://support.apple.com/en-ca/HT210650). I had the same issues on macbook pro and imac, which forced me to perform factory resets. I've given up on pyenv and decided to go with Anaconda to manage python versions.

Infusible answered 2/10, 2020 at 22:30 Comment(0)
B
0

Edit the file ~/.python-version and manually modify it to the version you want to switch.

Beckon answered 24/9, 2023 at 5:32 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Shifra

© 2022 - 2024 — McMap. All rights reserved.