Mac安装mod_wsgi报错:/usr/bin/clang执行失败,求助部署Django到Apache
clang failed with exit status 1 Error When Installing mod_wsgi Hey there, sorry to hear you're stuck on this clang error while setting up mod_wsgi for your Django project. Let's break down the most common fixes—this issue almost always ties back to missing dependencies, mismatched environments, or compiler tooling gaps.
1. Install Required Development Libraries
Mod_wsgi needs Apache's development headers and Python's core development files to compile successfully. Here's how to grab them for different systems:
Debian/Ubuntu-based systems:
sudo apt-get update sudo apt-get install apache2-dev python3-dev build-essential
RHEL/CentOS/Rocky Linux:
sudo yum update sudo yum install httpd-devel python3-devel gcc
macOS (using Homebrew):
brew install httpd python xcode-select --install # This ensures you have the latest clang and command line tools
2. Explicitly Point to Apache's APXS Tool
Sometimes the installer can't automatically locate Apache's apxs utility, which is critical for compiling mod_wsgi. First, find where apxs lives:
which apxs
Common paths are /usr/bin/apxs, /usr/local/apache2/bin/apxs, or /opt/homebrew/bin/apxs for M1/M2 Macs. Then install mod_wsgi with this path specified:
sudo pip install mod_wsgi --global-option="--with-apxs=/path/to/your/apxs"
3. Check Architecture Compatibility
Make sure your Python installation and Apache are both 32-bit or 64-bit—mismatches will break compilation. Verify with these commands:
# Check if Python is 64-bit (returns True if yes) python3 -c "import sys; print(sys.maxsize > 2**32)" # Check Apache's architecture httpd -V | grep -i "build"
If they don't match, you'll need to reinstall either Apache or Python to align their architectures.
4. Update mod_wsgi and Python Versions
Older mod_wsgi versions might not support newer Python releases (like 3.10+). Try upgrading to the latest mod_wsgi:
sudo pip install --upgrade mod_wsgi
If you're using a brand-new Python version, double-check mod_wsgi's release notes for compatibility—you might need a pre-release build if official support hasn't rolled out yet.
5. Refresh Clang Compiler Tools
If clang is still failing, ensure you have the latest compiler setup:
- On Linux: Update clang via your package manager (e.g.,
sudo apt-get install clangorsudo yum install clang) - On macOS: Re-run
xcode-select --installto refresh command line tools, or update Xcode through the App Store.
内容的提问来源于stack exchange,提问作者Steven Nestor

