Search code examples
pythonpython-3.xmacospyenv

How to use Python 3.5.1 with pyenv (on Mac)?


I installed Python 3.5.1 and then ran pyenv install 3.5.1, thinking this would point to Python 3.5.1. But that didn't work.

MBP-Oct-2016:~ user1$ python -V
Python 2.7.10
MBP-Oct-2016:~ user1$ pyenv versions
* system (set by /Users/user1/.pyenv/version)
  3.5.1

How do I get pyenv to make Python 3.5.1 the default version of Python?


Solution

  • Warning: Don't touch ~/.pyenv/version directly. That's not the recommended way.

    1. Initialize pyenv by putting the following content in your shell's init file. (~/.bash_profile for Bash on macOS, ~/.zshrc for ZSH).

      export PATH="$HOME/.pyenv/bin:$PATH"
      
      if command -v pyenv &>/dev/null; then
        eval "$(pyenv init -)"
      fi
      if command -v pyenv-virtualenv &>/dev/null; then
        eval "$(pyenv virtualenv-init -)"
      fi
      
    2. Open a new interactive shell, set Python 3.5.1 as the default Python with following command,

      pyenv global 3.5.1
      

    References