XCode CLI tools. Install with:
xcode-select --install
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