30

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

asked Oct 8, 2018 at 4:36
3
  • Is there a reason you are not using virtualenv instead? Commented Oct 8, 2018 at 4:57
  • Where would you like the files to be installed to? Isn't ~/Library/Python/2.7/lib/python/site-packages already user specific? Commented Oct 8, 2018 at 5:01
  • As I explained, I installed for lambda zip packaging. They need be installed in current directory and zipped in the lambda functions together. Commented Oct 8, 2018 at 5:41

1 Answer 1

52

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 .
answered Oct 8, 2018 at 5:17
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, this is the error I got DistutilsOptionError: must supply either home or prefix/exec-prefix -- not both when run your command
Nice, above url fixes the error DistutilsOptionError, I can install package locally now.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.