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?
I hit errors with the other recommendations around
--install-option="--prefix=lib"
. The only thing I found that worked is usingPYTHONUSERBASE
as described here.this is not exactly the same as
--target
, but it does the trick for me in any case.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 asetup.cfg
file in there and put the magic words inside:OK, now you sould be able to run pip's commands for that folder:
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 removesetup.cfg
.As other mentioned, this is known bug with pip & python installed with homebrew.
If you create
~/.pydistutils.cfg
file with "empty prefix" instruction it will fix this problem but it will break normal pip operations.Until this bug is officially addressed, one of the options would be to create your own bash script that would handle this case:
This script wraps your command and:
~/.pydistutils.cfg
file with "empty prefix" instruction in it~/.pydistutils.cfg
fileThis script can be changed and adapted to address your needs but you get idea. And it allows you to run your command without braking pip. Hope it helps :)
I have a similar issue. I use the --system flag to avoid the error as I decribe here on other thread where I explain the specific case of my situation. I post this here expecting that can help anyone facing the same problem.
Another solution* for Homebrew users is simply to use a
virtualenv
.Of course, that may remove the need for the target directory anyway - but even if it doesn't, I've found
--target
works by default (as in, without creating/modifying a config file) when in a virtual environment.*I say solution; perhaps it's just another motivation to meticulously use venvs...
On OSX(mac), assuming a project folder called /var/myproject
cd /var/myproject
setup.cfg
and add[install] prefix=
pip install <packagename> -t .