Skip to content

Instantly share code, notes, and snippets.

@findmory
Last active April 28, 2019 00:50
Show Gist options
  • Save findmory/1cb431c283a3de573f41f14784b5dfd7 to your computer and use it in GitHub Desktop.
Save findmory/1cb431c283a3de573f41f14784b5dfd7 to your computer and use it in GitHub Desktop.
Using Pyenv and virtualenv-wrapper for multiple Python versions on mac

Setup PyEnv on Mac

Prerequesties

XCode CLI tools. Install with:

xcode-select --install

Steps

1 install Homebrew Python to replace system version and also pyenv

brew install python

brew install pyenv

brew install pyenv-virtualenvwrapper

2 edit ~/.bash_profile to add

export PYENV_ROOT="$HOME/.pyenv"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)”  #this is for pyenv-virtualenv which you will install later

3 Use PyEnv to install a new version First check version names: pyenv install -- list

pyenv install 2.7.9

To check versions:

pyenv version

To install Python versions

pyenv install 2.7.9 (use pyenv install --list) note if you get an error you need to run this command sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

To change Python version globally

pyenv global 2.7.9

To change Python version locally (make it specific for a folder)

pyenv local 2.7.9

If using PyEnv-Virtualenvwrapper plugin do this:

Anytime we install a new version of Python, we will need to install virtualenvwrapper. This is done with either the pyenv virtualenvwrapper or pyenv virtualenvwrapper_lazy (preferred) command:

$ pyenv shell 3.6.2

$ pyenv virtualenvwrapper_lazy

To create a virtualenv for python ^^ Be sure to set the pyenv shell version.. then create the virtual env

mkvirtualenv your_env

workon your_env

deactivate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment