Notes

Python - Install pyenv on Mac

author: Paul Kim

categories: pyenv

tags: pyenv

Mac pre-install

# update homebrew
brew update
brew upgrade
brew doctor

# uninstall existing python3 and python2
brew uninstall python
brew uninstall python@2

# install pyenv dependencies
brew update
brew install readline xz

Install pyenv and pyenv-virtualenv on Mac

Install pyenv using Homebrew

# install using homebrew
brew install pyenv

# add pyenv init to your shell
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.bash_profile

# restart your shell
exec "$SHELL"

Homebrew installs pyenv in the following location

==> Downloading https://homebrew.bintray.com/bottles/pyenv-1.2.6.high_sierra.bot
######################################################################## 100.0%
==> Pouring pyenv-1.2.6.high_sierra.bottle.tar.gz
🍺  /usr/local/Cellar/pyenv/1.2.6: 607 files, 2.4MB

Install pyenv-virtualenv using Homebrew

# install using homebrew
brew install pyenv-virtualenv

# enable auto-activation of virtualenvs (optional)
echo 'if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi' >> ~/.bash_profile

# restart your shell
exec "$SHELL"

Homebrew installs pyenv-virtualenv in the following location

==> Downloading https://github.com/pyenv/pyenv-virtualenv/archive/v1.1.3.tar.gz
==> Downloading from https://codeload.github.com/pyenv/pyenv-virtualenv/tar.gz/v
######################################################################## 100.0%
==> ./install.sh
==> Caveats
To enable auto-activation add to your profile:
  if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi
==> Summary
🍺  /usr/local/Cellar/pyenv-virtualenv/1.1.3: 20 files, 62.2KB, built in 3 seconds

Suppress Homebrew warning about pyenv

Homebrew will complain about pyenv shims (see issue 106):

Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if
software packages are installed, and which additional flags to use when
compiling and linking.

To suppress warnings:

# suppress `brew doctor` warning about pyenv shims
# (https://github.com/pyenv/pyenv/issues/106)
alias brew='env PATH=${PATH//$(pyenv root)\/shims:/} brew'

Basically, your .bash_profile should look like this:

# pyenv pyenv-virtualenv
if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
  eval "$(pyenv virtualenv-init -)"
fi
# suppress `brew doctor` warning about pyenv shims
# (https://github.com/pyenv/pyenv/issues/106)
alias brew='env PATH=${PATH//$(pyenv root)\/shims:/} brew'

Upgrade pyenv and pyenv-virtualenv on Mac

brew upgrade pyenv
brew upgrade pyenv-virtualenv

Uninstall pyenv and pyenv-virtualenv on Mac

Disable pyenv and pyenv-virtualenv by removing the following lines from .bash_profile

# pyenv pyenv-virtualenv
if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
  eval "$(pyenv virtualenv-init -)"
fi
# suppress `brew doctor` warning about pyenv shims
# (https://github.com/pyenv/pyenv/issues/106)
alias brew='env PATH=${PATH//$(pyenv root)\/shims:/} brew'

Uninstall pyenv and pyenv-virtualenv by removing its root directory

Note: this will delete all Python versions that were installed under $(pyenv root)/versions/ directory.

# remove pyenv root directory to uninstall pyenv and pyenv-virtualenv
rm -rf $(pyenv root)

Remove pyenv and pyenv-virtualenv from homebrew

brew uninstall pyenv-virtualenv
brew uninstall pyenv

ChromeEdgeFirefoxOpera

© 2021 paulkode.com. All rights reserved.