How to Resolve Python Pip Error "setup.py bdist_wheel did not run successfully"
When installing Python packages, particularly those with C extensions or complex build requirements, you might encounter the error error: subprocess-exited-with-error
followed by × python setup.py bdist_wheel did not run successfully
. This indicates that pip
attempted to build a "wheel" (a standard distribution format for Python packages) from the package's source code using its setup.py
script, but the build process failed.
This guide details the common causes of this build failure and provides systematic solutions to resolve it.
Understanding the Error: Wheel Building Failure
Python packages can be distributed as pre-built "wheels" (.whl
files) or as source distributions (.tar.gz
, .zip
). When pip
cannot find a pre-built wheel compatible with your system (Python version, OS, architecture), it attempts to build one from the source distribution. This usually involves running the package's setup.py
script with the bdist_wheel
command.
The "python setup.py bdist_wheel did not run successfully" error means this build process, executed as a subprocess by pip
, failed and exited with a non-zero status code, indicating an error occurred during the build.
Common Causes
- Missing or Outdated Build Tools: The
wheel
package itself might be missing or outdated.setuptools
orpip
might also be too old. - Missing System Dependencies: The package requires external tools or libraries to compile source code (e.g., a C/C++ compiler like GCC/Clang/MSVC, development headers like
python3-dev
, libraries likelibpq-dev
for PostgreSQL). - Missing Build System: Some packages rely on build systems like
CMake
orRust
, which need to be installed separately. - Python Version Incompatibility: The package's
setup.py
or source code is incompatible with your current Python version. - Errors in
setup.py
: Bugs or configuration issues within the package's ownsetup.py
script. - Network Issues: Problems downloading build-time dependencies specified in
setup.py
orpyproject.toml
.
Solution 1: Ensure wheel
, setuptools
, and pip
are Up-to-Date (Crucial)
This is often the first and most effective step. Ensure you have the latest versions of the core packaging tools.
# Recommended command (targets the active Python environment's pip)
python -m pip install --upgrade pip setuptools wheel
# Alternatives (use pip/pip3 appropriate for your environment)
pip install --upgrade pip setuptools wheel
pip3 install --upgrade pip setuptools wheel
Retry the installation of your target package immediately after upgrading these.
Solution 2: Install Build Tools (cmake
, Compilers, Headers)
Many packages, especially in scientific computing, machine learning, or those interfacing with C/C++ libraries, require additional build tools.
Install cmake
via pip
If the error specifically mentions CMake, or if you suspect it's needed (common for C++ based packages):
python -m pip install cmake
# Or
pip install cmake
# Or
pip3 install cmake
While pip install cmake
works, sometimes system-installed CMake (sudo apt install cmake
, brew install cmake
) is preferred or required by specific packages. Check the package's documentation.
Install System-Level Build Dependencies
This is highly dependent on the package and your operating system. Look for messages in the full error output mentioning missing compilers (GCC, Clang, MSVC) or header files (.h
files, often in -dev
or -devel
packages).
-
Debian/Ubuntu:
sudo apt update
# Essential build tools & Python headers
sudo apt install build-essential python3-dev# Example: For packages needing PostgreSQL headers
sudo apt install libpq-dev
# Example: For packages needing OpenSSL headers
sudo apt install libssl-dev -
Fedora/CentOS/RHEL:
sudo dnf update # or yum
# Essential build tools & Python headers
sudo dnf groupinstall "Development Tools" # or yum groupinstall ...
sudo dnf install python3-devel# Example: For packages needing PostgreSQL headers
sudo dnf install libpq-devel
# Example: For packages needing OpenSSL headers
sudo dnf install openssl-devel -
macOS: Install Xcode Command Line Tools (provides Clang compiler):
xcode-select --install
# Use Homebrew (brew install ...) for other libraries if needed -
Windows: Install Microsoft C++ Build Tools (available via Visual Studio Installer -> Workloads -> "Desktop development with C++").
Consult the specific package's installation documentation for its required build dependencies. Install them, then retry the pip install
.
Solution 3: Check Python Version Compatibility
Ensure the package supports your Python version. Check PyPI or the package documentation. If incompatible, use a supported Python version (preferably in a virtual environment) or install an older, compatible version of the package (pip install PackageName==X.Y.Z
).
Solution 4: Address Package-Specific Dependencies (e.g., PyQt5)
Some packages have unique external dependencies. For example, PyQt5
or PyQt6
often require the underlying Qt framework libraries to be installed separately via system package managers (apt
, brew
, etc.) before pip install
will succeed. Always refer to the specific package's installation guide.
Solution 5: Use a Virtual Environment (Recommended)
Build issues can sometimes stem from conflicts with globally installed packages or permission problems. Isolating your project in a virtual environment is highly recommended.
# Create venv
python3 -m venv venv # Or python -m venv / py -m venv
# Activate venv
source venv/bin/activate # Example for Linux/macOS
# Ensure pip/setuptools/wheel are up-to-date WITHIN the venv
python -m pip install --upgrade pip setuptools wheel
# Install cmake if needed WITHIN the venv
python -m pip install cmake
# Try installing the target package again WITHIN the venv
python -m pip install YourTargetPackage
Solution 6: Modify setup.py
(If Building Your Own Package)
If the error occurs while building your own package:
- Ensure
wheel
is listed in yourpyproject.toml
under[build-system] requires = [...]
. - As a fallback for older systems or complex builds, you might need to explicitly add
setup_requires=['wheel']
within thesetup()
call in yoursetup.py
, although relying onpyproject.toml
is the modern standard.# setup.py (Less common now, prefer pyproject.toml)
from setuptools import setup
setup(
# ... other args ...
setup_requires=['wheel'] # Ensures wheel is available during setup execution
)
Debugging with Verbose Output (-vvv
)
Run pip install
with maximum verbosity to see the full output from the setup.py bdist_wheel
subprocess. This often reveals the exact compilation error or missing dependency.
# Replace YourTargetPackage with the actual package name
python -m pip install YourTargetPackage -vvv
Scroll through the (potentially long) output and look for error messages from compilers (gcc, clang, cl.exe), missing header file errors (.h not found
), or specific messages from setup.py
itself.
Deprecated Legacy Resolver (Less Common Fix for This Error)
Using pip install YourTargetPackage --use-deprecated=legacy-resolver
is unlikely to fix a bdist_wheel
build failure. It addresses dependency resolution issues, not compilation errors. Stick to the other solutions first.
Conclusion
The python setup.py bdist_wheel did not run successfully
error signals a failure during the package building process, usually when installing from source because a compatible pre-built wheel wasn't found.
Key steps to resolve it are:
- Upgrade
pip
,setuptools
, andwheel
: This is the most frequent fix. - Install
cmake
(pip install cmake
) if required by the package. - Install system-level build dependencies: Compilers (GCC, Clang, MSVC via Build Tools) and development headers (
python3-dev
, etc.) are often needed for packages with C/C++ extensions. Check the package docs and verbosepip
output for clues. - Check Python version compatibility.
- Use a virtual environment.
- Consult the specific package's installation instructions for any unique requirements.
- Use verbose
pip install -vvv
output to diagnose the exact build failure reason.
Addressing the build environment and ensuring all necessary tools and libraries are present is crucial for overcoming this error.