Search code examples
pythonpipaws-lambda

install python package at current directory


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


Solution

  • 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 .