Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you specify bin directory for pip install with --target option enabled

Tags:

python

pip

To give an example, if I run the command

sudo pip install gunicorn

There's now a file

/usr/local/bin/gunicorn

and a folder

/usr/local/lib/python2.7/site-packages/gunicorn

And I can run "gunicorn" from the shell.

However, if I run the command

sudo pip install gunicorn --target=~/tmp_directory

There's a folder at

 ~/tmp_directory/gunicorn

However, there is no "bin/gunicorn" anywhere and I cannot run "gunicorn" from the shell. Looking through the pip documentation I can't find anything for this particular case. The exact reason for my doing this is to try and setup a custom buildpack on Heroku.

like image 356
Scott Lobdell Avatar asked Oct 20 '14 23:10

Scott Lobdell


People also ask

What directory should I be in for pip install?

Generally you will need to specify --implementation, --platform, and --python-version when using this option. Install to the Python user install directory for your platform. Typically ~/.local/, or %APPDATA%Python on Windows.

How do I set pip to specify?

To install a specific version of a Python package you can use pip: pip install YourPackage==YourVersion . For example, if you want to install an older version of Pandas you can do as follows: pip install pandas==1.1. 3 .

Where is pip PATH stored?

By default, on Linux, Pip installs packages to /usr/local/lib/python2. 7/dist-packages. Using virtualenv or --user during install will change this default location.


2 Answers

I just found it's actually possible to tell 'pip' where to put scripts, data etc.

You can use --install-option to pass options to setuptools. So if you want to specify where to put scripts, you can:

pip install gunicorn --install-option="--install-scripts=$PWD/bin" -t python_modules/

Now you have gunicorn command inside bin/ in current directory and package installed in target dir python_modules.

bin/gunicorn
like image 122
chhantyal Avatar answered Sep 25 '22 12:09

chhantyal


You can sudo ln -s ~/tmp_directory/gunicorn /usr/bin/gunicorn.

If I understand your needs correctly, you're suggested to try virtualenv, a tool to create isolated Python environments. You can install different versions of Python packages for each of your project on the same server. Highly recommended for Python development. I'm using virtualenvwrapper, a wrapper to make it a bit easier to use

like image 24
ZZY Avatar answered Sep 22 '22 12:09

ZZY