Loading video player…

Installing pyenv

Here are resources for installing pyenv:

After installation your terminal configuration file should contain these lines:

export PATH="$HOME/.pyenv/bin:$PATH"
export PATH="$PYENV_ROOT/bin:$PATH"

if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"

00:00 In this lesson, you’re going to install pyenv, but before you can install pyenv itself, you’re going to need some operating system-specific dependencies.

00:12 These dependencies are mostly development utilities written in C and are required because pyenv installs Python by building from source.

00:23 In the Real Python article that comes with this course, you will find how to install build dependencies for the most common operating systems. You’ll find a link to this article in the description.

00:37 So now you can pause this video, move to the article to install the build dependencies, and then come back here to install pyenv.

00:48 Now that you’ve installed the build dependencies, you’re ready to install pyenv itself. I recommend using the pyenv-installer project, which is as simple as running the command displayed onscreen in your terminal.

01:04 If you’re using another shell like Zsh or Fish, then replace bash with the name of your shell. I have already installed pyenv, so I don’t have to run this command anymore.

01:19 Before we continue, you should check your terminal configuration file, which is—depending on the shell you’re using—~/.bashrc, ~/.zshrc, or ~/.profile.

01:31 It should contain something like the following, which sets the path to pyenv and initializes pyenv when you start the terminal.

01:42 I’ve noticed pyenv-installer change the commands a bit over time, but it should be similar. When your terminal configuration file doesn’t contain these commands, then you can copy them from this lesson’s description.

01:58 If you would like to know more about the pyenv-installer project, you will find a link to the project’s GitHub page in the description. A couple of plugins will be available to you after running pyenv-installer: pyenv, which is the actual pyenv application. pyenv-virtualenv, for creating and managing virtual environments with pyenv.

02:26 You will learn more about this plugin later in this course. pyenv-update, which is a plugin for updating pyenv itself and all pyenv plugins. pyenv-doctor, a plugin to verify that pyenv and build dependencies are installed. And finally, pyenv-which-ext, a plugin to automatically look up system commands. Now that everything is set up, let’s continue with installing a Python version using pyenv in the next lesson.

Avatar image for Raul C Pena

Raul C Pena on May 15, 2021

After following this I was given a terminal prompt to run pyenv init and it said to place this in the zsh profile:

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
Avatar image for danilolimadutra

danilolimadutra on March 3, 2024

I had problems installing the following dependencies for Ubuntu 22.04.

$ sudo apt-get install -y make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev \
libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl

E: Unable to locate package python-openssl

I had to change the python-openssl by python3-openssl.

Become a Member to join the conversation.