2020-03-08
|~2 min read
|326 words
I recently had to run an application built with Python 3.6. Unfortunately, when I looked at the installed version of python on my OS, it was 2.7
$ python --version
Python 2.7.17In Node-land, this is where something like nvm comes in handy for having different versions of node installed to easily move between them based on the project requirements.
(Side note: I got sick of using the wrong version to build my node projects, so I now check for a .nvmrc file every time I change directories.)
It turns out Python has a very similar tool called pyenv (and Ruby does too - rbenv).
Chris J Mendez has a great write-up on how use it to install multiple versions of python which was the main reference document I used to get up to speed.
The basic steps (using Homebrew) as Chris outlines them:
Update homebrew
brew updateInstall pyenv
brew install pyenvConfigure bash to use pyenv
If you want pyenv to run every time you boot up your terminal, you can add it to your bash_profile like so:
echo 'eval "$(pyenv init -)"' >> ~/.bash_profileAlternatively, you can add it as an alias:
alias runpyenv='eval "\$(pyenv init -)"'To have these changes take effect, you’ll need to refresh your terminal.
source ~/.bash_profileUse pyenv to install the version you need
List available versions
pyenv install --listInstall the desired version
pyenv install 3.8.0Set your version of python
Review which versions are installed
pyenv versionslocally
pyenv local 3.8.0globally
pyenv global 2.7.0Confirm your version is what you expect
python --versionYou may need to reload your terminal again to see the changes take effect.
Hi there and thanks for reading! My name's Stephen. I live in Chicago with my wife, Kate, and dog, Finn. Want more? See about and get in touch!