Skip to content
Latchkey

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.

pip output
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.

Terminal
# 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.txt

Clear a leaking --user default

If --target is what you want, unset the env var or pip.conf entry that forces --user.

Terminal
unset PIP_USER
pip config unset install.user   # if set in pip.conf
pip install --target ./build/python -r requirements.txt

How to prevent it

  • Choose one install destination per pipeline and document it.
  • Avoid global PIP_USER/pip.conf defaults that fight per-command flags.
  • Prefer a venv over --user/--target when you just need isolation.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →