Setting up Pyenv in .zshrc
~/.zshrc
# Activate Homebrew in the current shell session
eval "$(/opt/homebrew/bin/brew shellenv)"
# Set the PYENV_ROOT variable to point to the location of Pyenv
export PYENV_ROOT="$HOME/.pyenv"
# Check if pyenv command is available, if not, add Pyenv binary directory to PATH
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
# Initialize pyenv into the shell session
eval "$(pyenv init -)"
# Initialize pyenv-virtualenv plugin into the shell session
eval "$(pyenv virtualenv-init -)"
Setting up pyenv
- Install
pyenv
with Homebrew
brew update
brew install pyenv
- Define environment variable
PYENV_ROOT
to point to the path wherepyenv
will store its data.$HOME/.pyenv
is the default.
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
- Add the
pyenv
executable to yourPATH
if it's not already there
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
- Run
eval "$(pyenv init -)"
to installpyenv
into your shell as a shell function, enable shims and autocompletion- You may run
eval "$(pyenv init --path)"
instead to just enable shims, without shell integration
- You may run
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
Setting up pyevn-virtualenv
- Install
pyenv-virtualenv
via Homebrew
$ brew install pyenv-virtualenv
- Activate
pyenv-virtualenv
in the shell environment by appending the initialization script to the.zshrc
file:
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.zshrc