macOS环境下执行Django命令出现Segmentation fault:11错误求助
Hey, I’ve dealt with this exact segmentation fault problem on macOS High Sierra 10.13.2 with Python 3.6.5 before—since you’ve already tried the common fixes from unresolved threads, let’s dive into targeted solutions that actually worked for me and other devs:
1. Ditch sudo entirely (top recommended fix)
Segmentation faults here almost always stem from running Python/Django with elevated privileges, which breaks user-specific environment variables and package permissions that Python 3.6 relies on. Instead:
- Use a virtual environment (standard practice for Django projects anyway):
- Create a fresh venv:
python3 -m venv django_env - Activate it:
source django_env/bin/activate - Reinstall Django and all project dependencies inside the venv:
pip install django - Run your commands without sudo:
python manage.py migrateorpython manage.py runserver
- Create a fresh venv:
2. Reinstall Python 3.6.5 with the official installer
Broken Homebrew or system Python installations are a frequent culprit here. Try a clean reinstall using the official package:
- Uninstall your current Python 3.6 (if installed via Homebrew:
brew uninstall python@3.6) - Grab the Python 3.6.5 installer built for macOS High Sierra from the official Python release archive (avoid Homebrew for this step)
- Run the installer and ensure you check the "Add Python to PATH" option
- Create a new virtual environment and test your Django commands again
3. Downgrade Django to a compatible LTS version
Newer Django versions often drop support for older Python/macOS combinations. Pin Django to a version confirmed to work with Python 3.6:
- Inside your activated venv, run:
pip install django==2.2.28(this is the last LTS release fully compatible with Python 3.6) - Test your migrate/runserver commands once the installation finishes
4. Fix conflicting SQLite bindings
High Sierra’s system SQLite library is outdated and can clash with Django’s requirements. Replace it with a compatible binary:
- Inside your venv, uninstall any existing SQLite packages:
pip uninstall sqlite3 - Install the pre-compatible binary:
pip install pysqlite3-binary - Update your project’s
settings.pyto use this replacement instead of the system SQLite—add these lines at the very top:__import__('pysqlite3') import sys sys.modules['sqlite3'] = sys.modules.pop('pysqlite3') - Run your Django commands again to test
内容的提问来源于stack exchange,提问作者C.B.

