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.17
In 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 update
Install pyenv
brew install pyenv
Configure 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_profile
Alternatively, 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_profile
Use pyenv
to install the version you need
List available versions
pyenv install --list
Install the desired version
pyenv install 3.8.0
Set your version of python
Review which versions are installed
pyenv versions
locally
pyenv local 3.8.0
globally
pyenv global 2.7.0
Confirm your version is what you expect
python --version
You 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!