DistutilsOptionError must supply either home or prefix/exec-prefix -- not both
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
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

