Skip to content

Installing and setting up Python with pyenv

This is the backup Python setup

These instructions use pyenv instead of uv. If uv is working for you, use the regular Python installation guide instead.

Warning

If you run into problems using the command line, you might want to take a look at troubleshooting on the command line.

Prerequisites

Open the command line

First, you'll want to open up the command line.

Click the magnifying glass to open up Spotlight, then search for Terminal. Run it.

Open Windows Terminal, which we set up to use Git Bash.

Previously installed Pythons

You can run the following command exactly as it is written below to list all of the Pythons your command line can see.

which -a python

If it says something like python not found, congratulations! You have zero Pythons installed!

The first one in the list is the one that's used when python is typed.

This is just for reference: copy and paste the results somewhere. If we run into problems later, it might help us figure out what's going on.

That's it, you're good to go!

Another option is to use the Start Menu to open up Add and Remove Programs. Scroll down to find anything starting with Python.

If you find any, it might make sense to uninstall them now. I've especially had issues with old Python versions fighting new Python versions on Windows.

Package manager

One way to install software on your computer is to download software. Another way is to run commands on the command line, which uses a tool called a package manager.

Since we think the command line is cool, we're going to use that technique.

We'll be installing Homebrew from https://brew.sh/. They have a long line of text on their homepage that you cut and paste into Terminal, but to make your life easy I've reproduced it here:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

It might ask for your password by saying something like Password: []. Type your computer password and press enter.

If you type and type and nothing shows up... I promise, just type your password and hit enter! The command line is hiding your typing from anyone who might be looking at your screen.

Good news: Windows comes with a package manager called winget, so there's nothing to install!

Confirm it worked

To confirm Homebrew was installed, type the following command to check the documentation for the brew command.

brew help

Did it work? Great, you're good to go.

To confirm winget is ready to go, ask it for its version number.

winget --version

If it prints a version number, you're good to go. If it says command not found, open the Microsoft Store, search for App Installer, and install or update it.

Additional software

For pyenv to work at its best on macOS, we need to install a couple other pieces of software with Homebrew.

brew install openssl@3 readline sqlite3 xz zlib tcl-tk

Confirm it worked

Skim over what's written in the last twenty or so lines of the command line. Do you see any errors? Any "command not found?" If not, you're probably okay.

Nothing to install here, you can skip ahead!

Installing a Python installer

Now we're going to install the command pyenv. Pyenv allows us to juggle different Python versions easily.

For example, maybe you normally use the newest version of Python because it has great features. But then one day your colleague sends you some awful code that only works on an older Python! Pyenv makes that process simpler.

The traditional pyenv is for macOS only. Install by running the command below.

brew install pyenv

This step is only for people on macOS. Windows folks can skip ahead.

Now we need to make sure pyenv sets itself up every single time we open up a command line. To do this, you need to figure out what specific kind of command line you're using. Run the following command to find out:

echo $SHELL

What did it print out?

Copy and paste the following command to add setup instructions to ~/.zshrc, the setup file for the Z shell.

touch ~/.zshrc
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init - zsh)"' >> ~/.zshrc
source ~/.zshrc

Be sure to hit enter after the last one!

Copy and paste the following command to add setup instructions to ~/.bash_profile, the setup file for the Bash shell.

touch ~/.bash_profile
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(pyenv init - bash)"' >> ~/.bash_profile
source ~/.bash_profile

Be sure to hit enter after the last one!

pyenv for Windows is less popular than pyenv for macOS, but it works the same way.

We'll install it using these instructions here. This is the one time we need PowerShell: open the Start Menu, search for PowerShell, and run it. Then copy and paste the command below and press enter. You can check the documentation if you run into any problems.

Invoke-WebRequest -UseBasicParsing -Uri "https://raw.githubusercontent.com/pyenv-win/pyenv-win/master/pyenv-win/install-pyenv-win.ps1" -OutFile "./install-pyenv-win.ps1"; &"./install-pyenv-win.ps1"

If it complains about scripts being disabled, run Set-ExecutionPolicy RemoteSigned -Scope CurrentUser, type Y and hit enter, then try again.

When it's done, close PowerShell and open a new Windows Terminal (Git Bash) for the rest of these steps.

Confirm it worked

To confirm pyenv was installed correctly, run the following command to ask for its documentation.

pyenv help

If it prints anything other than "command not found" you're good to go.

Installing Python

We'll use Python 3.14, just like the main setup guide. The commands below use 3.14.5, which is listed by pyenv-win. If your installer lists a newer stable 3.14.something, use that version throughout instead. Avoid preview versions with a, b, or rc in their names.

To see which versions are available for you to install, run the following command:

pyenv install -l

Installing Python 3.14.5

The command below asks pyenv to install Python 3.14.5. If pyenv install -l shows a newer 3.14.something release, you can use that instead.

pyenv install 3.14.5

Warning

If you receive the error message configure: error: C compiler cannot create executables, it's because you are using an upgraded macOS version but some of the more technical parts also need to be updated. You can update this with the command below:

sudo rm -rf $(xcode-select -print-path)
xcode-select --install

Don't worry if it says it's going to take 60 hours to download and install! For some reason it's always lying. It will only take a few minutes.

Once that's done, try running the install command again.

Unfortunately, pyenv on Windows is usually a little behind the most recent releases! We'll update pyenv first, then ask it to install Python 3.14.5.

This process takes three steps:

  1. First, we'll update pyenv to know about all of the newer versions of Python. This might take a couple minutes, but don't worry, it's working.
  2. Then we'll install the Python version we're looking for. It will pop open a window about installing Python. Just agree to whatever it says.
  3. Finally, we'll use a command called "rehash" to make sure your computer notices the new Python.

The three commands to run one by one are:

pyenv update
pyenv install 3.14.5
pyenv rehash

Info

At the end of the installation there might be a button that says "Disable PATH length limit." Click it and agree to the prompt.

Confirm it worked

Run the following command to see a list of versions installed by pyenv.

pyenv versions

You should see Python 3.14.something in the list.

Selecting Python 3.14

Select the same version you installed above:

pyenv global 3.14.5
pyenv exec python --version

The second command should print Python 3.14.something. pyenv exec makes sure we're using the Python selected by pyenv, even if another environment is currently active.

Creating your data environment

We'll create the same shared data environment used by the main setup guide. This keeps the Jupyter and VS Code instructions the same whichever installer you used.

If you already see (data) at the beginning of your command line, shut down Jupyter and run deactivate first. If ~/.venvs/data already exists, move it aside before creating the new environment:

mv ~/.venvs/data ~/.venvs/data-backup-$(date +%Y%m%d-%H%M%S)

Skip that command if this is your first setup and the folder does not exist. The backup keeps the old environment's files; you'll reinstall packages in the new one.

pyenv exec python -m venv ~/.venvs/data
touch ~/.zshrc
grep -qxF 'source "$HOME/.venvs/data/bin/activate"' ~/.zshrc || echo 'source "$HOME/.venvs/data/bin/activate"' >> ~/.zshrc
source ~/.venvs/data/bin/activate

These commands assume the standard macOS Z shell. If you use Bash, put the activation line in ~/.bash_profile instead of ~/.zshrc.

Run these in Git Bash:

pyenv exec python -m venv ~/.venvs/data
[ -f ~/.bash_profile ] || echo '[ -f ~/.bashrc ] && . ~/.bashrc' > ~/.bash_profile
touch ~/.bashrc
grep -qxF 'source "$HOME/.venvs/data/Scripts/activate"' ~/.bashrc || echo 'source "$HOME/.venvs/data/Scripts/activate"' >> ~/.bashrc
grep -qxF 'export PYTHONUTF8=1' ~/.bashrc || echo 'export PYTHONUTF8=1' >> ~/.bashrc
source ~/.bashrc

Stop if creating the environment fails. After it succeeds, close the command line and open a new one. You should see (data).

Confirm it worked

which python
python --version
python -m pip --version

The paths should mention .venvs and data, and the version should be Python 3.14.something. If which python still points to a pyenv shim, the environment is not active yet.

Installing packages

Because this is the fallback for when uv isn't working, use Python's built-in pip command:

python -m pip install pandas

This installs into your active data environment. Check it with:

python -c "import pandas; print(pandas.__file__)"

The path should mention .venvs and data. If uv works again later, uv pip install pandas can install into this same environment too.

You're all set!

Next up: install Jupyter. Use the pyenv fallback install command on that page, then follow the same kernel and VS Code instructions as everyone else.