Error: metadata-generation-failed python

Are you getting the error “metadata-generation-failed”? Yes, you have come to the right place. In this tutorial, I will show you how to resolve this error: “metadata generation failed.”

The error “metadata-generation-failed. Encountered error while generating package metadata” occurs for multiple reasons:

  • Outdated version of pip and setuptools.
  • Having an unsupported version of Python with the package you are installing.
  • Misspelling package name, double check your package name.
  • Package dependencies are missing.

We get an error something like this:

error: subprocess-exited-with-error

× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [1 lines of output]
    ERROR: Can not execute `setup.py` since setuptools is not available in the build environment.
    [end of output]

error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

[Fixed]: metadata-generation-failed

The first solution to this error is to use the –use-deprecated option with the pip install command.

pip install requests --use-deprecated=legacy-resolver
pip3 install requests --use-deprecated=legacy-resolver

python -m pip install requests --use-deprecated=legacy-resolver
python3 -m pip install requests --use-deprecated=legacy-resolver
py -m pip install requests --use-deprecated=legacy-resolver

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

[Fixed]: ModuleNotFoundError: No module named ‘scipy’

[Fixed]: metadata generation failed

If the above solution did not solve your issue you can try to set the –use-deprecated option to backtrack-on-build-failures.

pip install requests --use-deprecated=backtrack-on-build-failures
pip3 install requests --use-deprecated=backtrack-on-build-failures

python -m pip install requests --use-deprecated=backtrack-on-build-failures
python3 -m pip install requests --use-deprecated=backtrack-on-build-failures

[Solution]: metadata-generation-failed python

If your problem is still not resolved, you need to upgrade your PIP version. You can upgrade pip using the below commands according to your OS requirements.

# if you have pip already installed
pip install --upgrade pip

# if your pip is aliased as pip3 (Python 3)
pip3 install --upgrade pip

# if you don't have pip in your PATH environment variable
python -m pip install --upgrade pip

# if you don't have pip in your PATH environment variable
python3 -m pip install --upgrade pip

# if you have easy_install
easy_install --upgrade pip

# if you get a permissions error
sudo easy_install --upgrade pip

# if you get a permissions error
pip install --upgrade pip --user

# upgrade pip for the current user
python -m pip install --user --upgrade pip
python3 -m pip install --user --upgrade pip

# Installing pip directly from get-pip.py (MacOS and Linux)
curl https://bootstrap.pypa.io/get-pip.py | python

# if you get permissions issues you can use this command
curl https://bootstrap.pypa.io/get-pip.py | sudo python

# alternative for Ubuntu/Debian
sudo apt-get update && apt-get upgrade python-pip

# alternative for Red Hat / CentOS / Fedora
sudo yum install epel-release
sudo yum install python-pip
sudo yum update python-pip

When you upgrade the PIP, you also need to upgrade ‘setuptools‘ and ‘wheels‘. You can update these packages by using these commands.

pip install --upgrade setuptools wheel

pip3 install --upgrade setuptools wheel

python3 -m pip install --upgrade setuptools wheel

Conclusion on metadata generation failed python

Programmers, we discussed how we can solve the error “metadata generation failed python”. If you are still facing the error please let us know in the comments section. The error “metadata-generation-failed. Encountered error while generating package metadata” occurs for multiple reasons. You can apply above fixes to get rid of this error.

Leave a Reply