DEV Community


Using pyenv to install Python and create a virtual environment

Andrea Grandi
My name is Andrea Grandi and I live in Italy. I work remotely as Python/Django developer for LaterPay.
・2 min read

A few days ago Python 3.9.0 has been released and I really wanted to test ist latest features (maybe I will do a separate post to talk about them) without messing my system with another Python version.

To manage my Python versions I've been using pyenv for a while and once configured, it's very easy to install a new Python version.

Make sure your pyenv is updated

You should have at least pyenv 1.2.21 if you want to test Python 3.9.0

In case you haven't updated it and you are using MacOS, you can do it with this command:

brew update && brew upgrade pyenv

once installed you should see the latest version:

pyenv --version
pyenv 1.2.21

Install Python 3.9.0

To install Python 3.9.0 you only need pyenv install 3.9.0:

pyenv install 3.9.0
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.9.0.tar.xz...
    Installing Python-3.9.0...
    python-build: use readline from homebrew
    python-build: use zlib from xcode sdk
    Installed Python-3.9.0 to /Users/andrea/.pyenv/versions/3.9.0

Set Python 3.9.0 as the local version

Now that the version you want has been installed, you need to tell pyenv you want to use it:

pyenv local 3.9.0
pyenv which python

You can find the rest of the tutorial on my blog

Discussion (0)

Forem Open with the Forem app