pip "Can not combine '--user' and '--target'" in CI
pip’s install-location flags - --target, --prefix, and --user - each redirect where packages land, and pip refuses to honor more than one at a time. Passing two together is an immediate error.
What this error means
pip aborts before installing with ERROR: Can not combine '--user' and '--target' (or --prefix and --target). Nothing installs because pip rejects the contradictory destination flags up front.
ERROR: Can not combine '--user' and '--target'Common causes
Two destination flags passed together
--target DIR, --prefix DIR, and --user each pick a distinct install root. pip treats them as mutually exclusive and errors rather than guessing which you meant.
A global flag leaking from PIP_* env or pip.conf
A PIP_USER=1 env var or a user = true line in pip.conf silently adds --user to every command, so an explicit --target then collides with it.
How to fix it
Pick a single destination
For a bundled lambda/layer build use --target; for a per-user install use --user. Never both.
# vendor deps into a build dir (Lambda layer, zipapp)
pip install --target ./build/python -r requirements.txt
# OR a user install - not together
pip install --user -r requirements.txtClear a leaking --user default
If --target is what you want, unset the env var or pip.conf entry that forces --user.
unset PIP_USER
pip config unset install.user # if set in pip.conf
pip install --target ./build/python -r requirements.txtHow to prevent it
- Choose one install destination per pipeline and document it.
- Avoid global
PIP_USER/pip.confdefaults that fight per-command flags. - Prefer a venv over
--user/--targetwhen you just need isolation.