Skip to content

Check if a package will install in another version of Python

Also known as (potentially) solving the "Could not build wheels for [package]" error message.

The problem

Sometimes when you try to install a package you get an error. What's the error? Could be anything!

A big one is "couldnot build wheels for [package]," which means two things:

  1. pip couldn't find a version of the package pre-built for your system (combination of your Python version + your operating system)
  2. It tried to take the source code and turn it into a package, but something went wrong.

Figuring out the second half is probably the "correct" way to fix things long term, but changing your Python version is often a quicker fix if there happens to be a pre-built version for another.

Update pyenv

Did you install Python using pyenv?. I hope so, because we're going to take advantage of that!

We'll start by updating all of the Pythons that pyenv knows about.

How did you install pyenv? Don't worry if you aren't sure: running both methods won't cause any problems.

brew update pyenv
pyenv update

Determining which other Python version to try

First,check the version of Python you're running:

python --version

Then, find the versions of Python that pyenv knows about:

pyenv install --list

Scroll all the way up to the top to see something that looks a little bit earlier than yours.

For example, if I'm using 3.11.8 I might want to dial back to 3.10.13.

Installing and testing

Since we are interested in scaling back to Python 3.10.13, we'll start by installing Python 3.10.13 with pyenv.

pyenv install 3.10.13

Then we'll try to install the dedupe package just for Python 3.10.13.

PYENV_VERSION=3.10.13 pyenv exec pip install dedupe

Did it work? If so, you might want to change your version permanently to that other version of Python.

pyenv global 3.10.13

Cleanup

If you change the version of Python you're using, you'll probably end up having to reinstall a lot of packages for your new Python version, along with setting up Jupyter to point to the right place.

# Reinstall some libraries
pip install requests bs4 pandas

# Change Jupyter to use the current command-line Python
python -m pip install ipykernel
python -m ipykernel install --user