Could not build wheels for backports.zoneinfo, which is required

avatar
Borislav Hadzhiev

Last updated: Apr 9, 2024
2 min

banner

# Could not build wheels for backports.zoneinfo, which is required

The error "Could not build wheels for backports.zoneinfo, which is required to install pyproject.toml-based projects" occurs because the backports.zoneinfo module doesn't support Python versions greater than 3.9.

To solve the error, use version 3.8 instead.

shell
ERROR: Failed building wheel for backports.zoneinfo Failed to build backports.zoneinfo ERROR: Could not build wheels for backports.zoneinfo, which is required to install pyproject.toml-based projects

The error is caused because the backports.zoneinfo module is not supported in Python 3.9+.

If you got the error when deploying to Heroku:

  1. Create a runtime.txt file in your app's root directory.
  2. Specify a Python 3.8.x supported runtime in the file, e.g. python-3.8.15. You can view all of the supported runtimes in this section of the docs.
  3. Push the changes with git push heroku master.

The runtime.txt file is case-sensitive and must not include spaces.

runtime.txt
python-3.8.15

Make sure to pick one of the supported runtimes for Python 3.8.X.

If you need to view your local version of Python, run the python --version command.

shell
python --version

If you don't use Heroku, update your requirements.txt file and replace the following line:

requirements.txt
backports.zoneinfo==0.2.1

With the following line.

requirements.txt
backports.zoneinfo;python_version<"3.9"

This declares a dependency on the backports.zoneinfo module conditional on the Python version.

If you get the error when using docker, use an exact version of Python that is 3.8.X, e.g. 3.8.15.

If none of the suggestions helped, you can downgrade your Python version to 3.9.0.

# Using an older version of Python

You can check your Python version with the python --version command.

shell
python --version

get python version

Different versions are available in the "Looking for a specific release" table.

install specific python version

If you have Python 3.9.0 installed, you can initialize a virtual environment using the specific version.

shell
# ๐Ÿ‘‡๏ธ Use the correct version of Python when creating VENV python3.9 -m venv venv # ๐Ÿ‘‡๏ธ Activate on Unix or MacOS source venv/bin/activate # ๐Ÿ‘‡๏ธ Activate on Windows (cmd.exe) venv\Scripts\activate.bat # ๐Ÿ‘‡๏ธ Activate on Windows (PowerShell) venv\Scripts\Activate.ps1 # ๐Ÿ‘‡๏ธ Install the specific package in the virtual environment pip install requests

Make sure to use the correct command to activate your virtual environment depending on your operating system and your shell.

Your virtual environment will use the version of Python that was used to create it.

# Try running pip install in verbose mode

If none of the suggestions helped, try running the pip install command in verbose mode.

shell
pip install requests -vvv pip3 install requests -vvv python -m pip install requests -vvv

run pip install command in verbose mode

The -v option stands for verbose mode and can be used up to 3 times.

When the pip install command is run in verbose mode, the command shows more output and how the error occurred.

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2024 Borislav Hadzhiev