DistutilsOptionError: must supply either home or prefix/exec-prefix — not both

StackOverflow

I"ve been usually installed python packages through pip.

For Google App Engine, I need to install packages to another target directory.

I"ve tried:

pip install -I flask-restful --target ./lib

but it fails with:

must supply either home or prefix/exec-prefix -- not both

How can I get this to work?

Answer rating: 290

Are you using OS X and Homebrew? The Homebrew python page https://github.com/Homebrew/brew/blob/master/docs/Homebrew-and-Python.md calls out a known issue with pip and a work around.

Worked for me.

You can make this "empty prefix" the default by adding a ~/.pydistutils.cfg file with the following contents:

[install]
prefix=

Edit: The Homebrew page was later changed to recommend passing --prefix on the command line, as discussed in the comments below. Here is the last version which contained that text. Unfortunately this only works for sdists, not wheels.

The issue was reported to pip, which later fixed it for --user. That"s probably why the section has now been removed from the Homebrew page. However, the problem still occurs when using --target as in the question above.

Answer rating: 164

I believe there is a simpler solution to this problem (Homebrew"s Python on macOS) that won"t break your normal pip operations.

All you have to do is to create a setup.cfg file at the root directory of your project, usually where your main __init__.py or executable py file is. So if the root folder of your project is: /path/to/my/project/, create a setup.cfg file in there and put the magic words inside:

[install]
prefix=  

OK, now you sould be able to run pip"s commands for that folder:

pip install package -t /path/to/my/project/  

This command will run gracefully for that folder only. Just copy setup.cfg to whatever other projects you might have. No need to write a .pydistutils.cfg on your home directory.

After you are done installing the modules, you may remove setup.cfg.





Tutorials