Preparing metadata (pyproject.toml) did not run successfully

avatar
Borislav Hadzhiev

Last updated: Apr 10, 2024
5 min

banner

# Preparing metadata (pyproject.toml) did not run successfully

To solve the "Preparing metadata (pyproject.toml) did not run successfully" error:

  1. Make sure your Python version is supported by the package.
  2. Upgrade your versions of pip, setuptools and wheel.
  3. Make sure you haven't got any missing dependencies.
  4. Try running the pip install command with the --pre option.
shell
Preparing metadata (pyproject.toml) ... error error: subprocess-exited-with-error ร— Preparing metadata (pyproject.toml) did not run successfully. โ”‚ exit code: 1

If you got the error when trying to install PyQt5 on macOS:

  1. Run the brew install qt5 command to install qt5.
  2. Add the directory where qmake is located to your PATH environment variable.
.bash_profile
export PATH=$PATH:<path_to_qmake>
If you can't locate qmake, try running the following command, which will symlink the qt5 binaries and enable you to access qmake at the command line without the need to edit your PATH.
shell
brew link qt5 --force

# Try upgrading your versions of pip, setuptools and wheel

First, try to upgrade your versions of pip, setuptools and wheel.

shell
pip install wheel setuptools pip --upgrade pip3 install wheel setuptools pip --upgrade # ๐Ÿ‘‡๏ธ If you don't have `pip` in your PATH environment variable python -m pip install wheel setuptools pip --upgrade python3 -m pip install wheel setuptools pip --upgrade py -m pip install wheel setuptools pip --upgrade

upgrade wheel setuptools pip

Try to run the pip install command after you have upgraded pip, setuptools and wheel.

# Using the --use-deprecated-legacy option when installing

If that didn't help, try running the pip install command with the --use-deprecated-legacy option.

shell
pip install numpy --use-deprecated=legacy-resolver pip3 install numpy --use-deprecated=legacy-resolver python -m pip install numpy --use-deprecated=legacy-resolver python3 -m pip install numpy --use-deprecated=legacy-resolver py -m pip install numpy --use-deprecated=legacy-resolver # -------------------------------------------------------------- # ๐Ÿ‘‡๏ธ Set to backtrack-on-build-failures for older versions of pip pip install numpy --use-deprecated=backtrack-on-build-failures pip3 install numpy --use-deprecated=backtrack-on-build-failures python -m pip install numpy --use-deprecated=backtrack-on-build-failures python3 -m pip install numpy --use-deprecated=backtrack-on-build-failures

pip install using legacy resolver

Make sure to replace numpy with the name of the package you're trying to install.

The --use-deprecated option allows us to use the old resolver behavior when installing modules.

# Your error message might contain additional instructions

If the suggestions didn't help, read toward the end of your error message.

It might contain information such as:

  • "RuntimeError: Cannot install on Python version 3.11.0; only versions >=3.7,<3.11 are supported."

  • "RuntimeWarning: NumPy X.Y.Z may not yet support Python 3.11"

In this case, you can try to:

  1. Remove the specific version of the package from your requirements.txt file.
  2. Install an older version of the package, e.g. pip install requests==2.28.0.
  3. Use a Python version that is supported by the package.

# Having a required, missing package

Your error message might also contain a missing package you have to install, e.g. "ModuleNotFoundError: No module named 'X'" or "ImportError: cannot import name 'X'".

If that's the case, you have to pip install the package from the error message before installing the other package.

shell
pip install <package_from_error_message> pip3 install <package_from_error_message>

# Misspelling the name of the package

Another common cause of the error is misspelling the name of the package and trying to install some broken, obsolete module by mistake.

# Run the pip install command with the --pre option

If none of the suggestions helped, try running the pip install command with the --pre option.

shell
pip install scikit-learn --pre pip3 install scikit-learn --pre python -m pip install scikit-learn --pre python3 -m pip install scikit-learn --pre py -m pip install scikit-learn --pre

install package with pre option

The --pre option makes it so pip includes pre-release and development versions of the package. By default pip only finds stable versions.

# Installing a specific version of the package

If the suggestions didn't help, try installing another version of the package.

shell
pip install requests==

pip list all available versions of package

The output contains a tuple of all of the versions of the package from the oldest to the most recent version.

Pick another version of the package and try installing it. Here is an example.

shell
pip install requests==2.28.0 pip3 install requests==2.28.0

If you use Anaconda, follow the instructions in my Install a specific package version using conda article.

# Use the --extra-index option when installing scikit-learn

If you got the error while trying to install scikit-learn, try running the command with the --pre and --extra-index options.

shell
pip install --pre --extra-index https://pypi.anaconda.org/scipy-wheels-nightly/simple scikit-learn

The command installs the nightly build of scikit-learn where bugs might have been fixed.

The most common cause of the error is having a Python version that is not supported by the package you're trying to install.

# Check if your Python version is supported by the package

The error is sometimes caused when the package you are trying to install doesn't have available wheels for your version of Python.

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

shell
python --version

get python version

You can check if a package has wheels available for a specific Python version in the Download files section of the package's pypi page.

For example, cp310 in the name of a file under "Built Distributions" means Python version 3.10 is supported for the specific operating system.

If the .whl files are not available for your version of Python, you can download an older version.

# Downloading a specific Python version that is supported by the package

If that didn't work, you can download a specific Python version that is supported by the package if the package doesn't support the latest Python version.

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

install specific python version

Make sure to tick the following options if you get prompted:

  • Install launcher for all users (recommended)
  • Add Python to PATH (this adds Python to your PATH environment variable)

# Create a virtual environment

If that didn't help and you don't already have a virtual environment, try creating one.

  1. Create a virtual environment.
  2. Activate the virtual environment.
  3. Run the pip install command with the virtual environment active.
shell
# ๐Ÿ‘‡๏ธ Use the correct version of Python when creating VENV python3 -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 # ๐Ÿ‘‡๏ธ Upgrade pip pip install --upgrade pip # ๐Ÿ‘‡๏ธ Install the specific package in the virtual environment pip install requests

If the python3 -m venv venv command fails, try one of the following commands:

  • python -m venv venv
  • py -m venv venv

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

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