DEV Community 👩‍💻👨‍💻

Andrea Grandi
Andrea Grandi

Posted on

Using pyenv to install Python and create a virtual environment

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...
-> https://www.python.org/ftp/python/3.9.0/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
/Users/andrea/.pyenv/versions/3.9.0/bin/python

You can find the rest of the tutorial on my blog https://www.andreagrandi.it/2020/10/10/install-python-with-pyenv-create-virtual-environment-with-specific-python-version/

Top comments (0)

🌚 Browsing with dark mode makes you a better developer.

It's a scientific fact.