Homebrew in macOS
Update homebrew and install pyenv:
brew update brew install pyenvIf you want to install (and update to) the latest development head of Pyenv rather than the latest release, instead run:
brew install pyenv --headThen follow the rest of the post-installation steps, starting with Set up your shell environment for Pyenv.
OPTIONAL. To fix
brew doctor
's warning ""config" scripts exist outside your system or Homebrew directories"If you're going to build Homebrew formulae from source that link against Python like Tkinter or NumPy (This is only generally the case if you are a developer of such a formula, or if you have an EOL version of MacOS for which prebuilt bottles are no longer provided and you are using such a formula).
To avoid them accidentally linking against a Pyenv-provided Python, add the following line into your interactive shell's configuration:
Bash/Zsh:
alias brew='env PATH="${PATH//$(pyenv root)\/shims:/}" brew'Fish:
alias brew="env PATH=(string replace (pyenv root)/shims '' \"\$PATH\") brew"
The below setup should work for the vast majority of users for common use cases. See Advanced configuration for details and more configuration options.
Stock Bash startup files vary widely between distributions in which of them source which, under what circumstances, in what order and what additional configuration they perform. As such, the most reliable way to get Pyenv in all environments is to append Pyenv configuration commands to both
.bashrc
(for interactive shells) and the profile file that Bash would use (for login shells).
First, add the commands to
~/.bashrc
by running the following in your terminal:echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc echo 'eval "$(pyenv init - bash)"' >> ~/.bashrcThen, if you have
~/.profile
,~/.bash_profile
or~/.bash_login
, add the commands there as well. If you have none of these, create a~/.profile
and add the commands there.
- to add to
~/.profile
:echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.profile echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profile echo 'eval "$(pyenv init - bash)"' >> ~/.profile- to add to
~/.bash_profile
:echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile echo 'eval "$(pyenv init - bash)"' >> ~/.bash_profileBash warning: There are some systems where the
BASH_ENV
variable is configured to point to.bashrc
. On such systems, you should almost certainly put theeval "$(pyenv init - bash)"
line into.bash_profile
, and not into.bashrc
. Otherwise, you may observe strange behaviour, such aspyenv
getting into an infinite loop. See #264 for details.echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc echo 'eval "$(pyenv init - zsh)"' >> ~/.zshrcIf you wish to get Pyenv in noninteractive login shells as well, also add the commands to
~/.zprofile
or~/.zlogin
.
If you have Fish 3.2.0 or newer, execute this interactively:
set -Ux PYENV_ROOT $HOME/.pyenv fish_add_path $PYENV_ROOT/binOtherwise, execute the snippet below:
set -Ux PYENV_ROOT $HOME/.pyenv set -U fish_user_paths $PYENV_ROOT/bin $fish_user_pathsNow, add this to
~/.config/fish/config.fish
:pyenv init - fish | source
for the
PATH
changes to take effect.exec "$SHELL"
Are you really advising people to update their shell config files by running commands like
ReplyDeleteecho 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
???
That strikes me as incredibly ill advised. If someone is so helpless that they don't know how to open their .zshrc file with a text editor and edit it in the appropriate way, I can't imagine that using pyenv, or almost any development tool, is going to be a smooth ride.