DistutilsOptionError must supply either home or prefix/exec-prefix -- not both
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
The error DistutilsOptionError: must supply either home or prefix/exec-prefix -- not both occurs when Python's distutils (or setuptools) receives conflicting installation path options. This typically happens on macOS with Homebrew Python, where the system sets --prefix via a config file while pip or the user passes --home. The fix is to create or edit ~/.pydistutils.cfg (or setup.cfg) to remove the conflicting option, or use virtual environments which avoid path conflicts entirely.
The Error
Why This Happens
Python's distutils supports two mutually exclusive installation schemes:
--home— installs to a single directory (e.g.,--home=/usr/local)--prefix— installs to a directory with Unix-style subdirectories (lib/,bin/, etc.)
When both are set — one by a config file and one by the command line — distutils refuses to proceed.
The most common scenario is on macOS with Homebrew Python:
When pip then tries to install with --home, the two options conflict.
Fix 1: Create ~/.pydistutils.cfg (macOS/Homebrew)
This empties the prefix setting, allowing --home to work. Alternatively:
Fix 2: Use a Virtual Environment (Recommended)
Virtual environments have their own isolated distutils config and avoid path conflicts:
This is the cleanest fix because virtual environments do not inherit system-level distutils configuration.
Fix 3: Use --prefix Only
If you need to install to a specific location, use --prefix consistently:
Do not mix --home and --prefix in the same installation.
Fix 4: Set PYTHONUSERBASE
For user-level installations without root:
The --user flag uses a separate installation scheme that does not conflict with --home or --prefix.
Fix 5: Environment Variable Override
Diagnosing the Conflict
Python 3.12+: distutils Removed
Starting with Python 3.12, the distutils module was removed from the standard library. The setuptools package provides its own distutils:
Common Pitfalls
- Editing the system distutils.cfg instead of user config: The system
distutils.cfg(inside the Python installation directory) affects all users. Edit~/.pydistutils.cfgfor user-specific fixes, which takes precedence over the system config without affecting other users. - Using sudo pip install: Running
sudo pip installon macOS with Homebrew Python changes the effective user and may bypass~/.pydistutils.cfg. Avoidsudo pipentirely — use virtual environments or--userinstead. Mixingsudoand non-sudopip installs causes permissions chaos. - Forgetting to activate the virtual environment: Creating a venv with
python3 -m venv myenvdoes not activate it. Runningpip installwithoutsource myenv/bin/activatefirst still uses the system Python and hits the same config conflict. - Homebrew Python upgrade resetting config: Upgrading Python via
brew upgrade pythoninstalls a new version with its owndistutils.cfg. After upgrading, the conflict may reappear even if you fixed it before. Re-apply the fix or use virtual environments which survive upgrades. - Assuming the error is in your package: This error comes from Python's installation machinery, not from the package you are trying to install. The package's
setup.pyorpyproject.tomlis not at fault. The fix is always in the Python/distutils configuration, not in the package itself.
Summary
- The error occurs when
--homeand--prefixinstallation options conflict in distutils config - Most common on macOS with Homebrew Python, which sets
prefixindistutils.cfg - Fix by creating
~/.pydistutils.cfgwithprefix=(empty) or removing the file - Best fix: use virtual environments (
python3 -m venv) which avoid all path conflicts - Use
pip install --userfor user-level installations without root - Python 3.12+ removed
distutils—setuptoolsprovides it, but the same fix applies
Related reading
- Django-celery and RabbitMQ not executing tasks
- django-storages with multiple S3 Buckets
- Django - Executing a task through celery from a model
- Django - How to rename a model field using South?
- Django - makemigrations - No changes detected
- Django Celery tutorial not returning results
- Django - what is the difference between render, render_to_response and direct_to_template?
- Django Admin - Disable the 'Add' action for a specific model
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.