25

I am mac user, used to run pip install with --user, but recently after brew update, I found there are some strange things, maybe related.

Whatever I tries, the packages are always installed to ~/Library/Python/2.7/lib/python/site-packages

Here are the commands I run.

$ python -m site --user-site
~/Library/Python/2.7/lib/python/site-packages

$ pip install --user -r requirements.txt

$ PYTHONUSERBASE=. pip install --user -r requirements.txt

So what should be the problem?

I used for lambda zip packaging

Updates:

If using Mac OS X and you have Python installed using Homebrew (see Homebrew), the accepted command will not work. A simple workaround is to add a setup.cfg file in your /path/to/project-dir with the following content.

[install]
prefix=

https://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html

Bill
  • 2,494
  • 5
  • 26
  • 61
  • Is there a reason you are not using `virtualenv` instead? – tripleee Oct 08 '18 at 04:57
  • Where would you like the files to be installed to? Isn't `~/Library/Python/2.7/lib/python/site-packages` already user specific? – FlyingTeller Oct 08 '18 at 05:01
  • As I explained, I installed for lambda zip packaging. They need be installed in current directory and zipped in the lambda functions together. – Bill Oct 08 '18 at 05:41

1 Answers1

43

You can use the target (t) flag of pip install to specify a target location for installation.

In use:

pip install -r requirements.txt -t /path/to/directory

to the current directory:

pip install -r requirements.txt -t .
Henry Woody
  • 14,024
  • 7
  • 39
  • 56
  • Thanks, this is the error I got `DistutilsOptionError: must supply either home or prefix/exec-prefix -- not both` when run your command – Bill Oct 08 '18 at 05:39
  • maybe related to this: https://stackoverflow.com/questions/24257803/distutilsoptionerror-must-supply-either-home-or-prefix-exec-prefix-not-both – Bill Oct 08 '18 at 05:43
  • Nice, above url fixes the error `DistutilsOptionError`, I can install package locally now. – Bill Oct 08 '18 at 05:44