Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pip install python package into a specific directory other than the default install location

The default location where pip installes packages on my Ubuntu system is '/usr/local/lib/pytho2.7/dist-packages/' which I think is the default in general. I am using Enthought python distribution (EPD not canopy) and would like to install a package into EPD as I usually work with the python from the EPD distribution on my system. I would like to know into which directory inside EPD the new files need to be installed using pip ; as the directory structure for EPD on linux seems to be quite different from the EPD directory structure on MAC OS for where there seem to be many examples.

Also I have come across this :

pip install --install-option="--prefix=$PREFIX_PATH" package_name

as the accepted answer to a question similar to this. I would like to know what the purpose of the $PREFIX_PATH environment variable is as mine is currently blank. And what path I need to specify on Ubuntu for my Enthought EPD distribution to install python modules.

I apologize for the relatively naive question but I am quite new to EPD on ubuntu and am still trying to figure it out.

like image 427
user2502020 Avatar asked Jun 20 '13 14:06

user2502020


People also ask

How do I install Python in a different location?

To change install location, click on Customize installation , then Next and enter C:\python35 (or another appropriate location) as the install location. If you didn�t check the Add Python 3.5 PATH option earlier, check Add Python to environment variables .

How do I install pip in a specific environment?

For the environments use https://conda.io/docs/user-guide/tasks/manage-environments.html to activate the desired environment, then you can pip install or conda install the packages and it will be places safely only in that environment.

How do I change the download location for pip?

Click on the Advanced system settings link on the left panel. Click Environment Variables. Under System Variables, double-click the variable PATH. Click New, and add the directory where pip is installed, e.g. C:Python\Scripts, and select OK.

How does pip decide where to install?

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. If you use pip show make sure you are using the right user or else pip may not see the packages you are referencing.


2 Answers

This line should work for everyone, as mentioned in the documentation.

pip install package_name -t any/path/i/like 

PS:

And to address the comment of @CPiLL, the any/path/i/like can really be anything, such as /tmp/my-test-env. The package being installed in this way will NOT be available for your usual python environment, in fact they will NOT even show up using pip list. And python -c "import package_name" will generally FAIL with ImportError exception, unless you cd into that folder first:

cd /tmp/my-test-env python -c "import package-name" 

How this technique would be useful is beyond this answer.

like image 128
RayLuo Avatar answered Sep 23 '22 00:09

RayLuo


System: Ubuntu 12.04, Enthought Python Distribution (this is where I wanted to install a new python module)

So the prefix_path environment variable didn't work for me and pip still kept installing it in the default location. But I used How do I change the default directory that pip installs to?

question as a guide. And one of the answers helped me achieve what I needed.

 pip install -d <path_to_my_directory>   

For the path I used: path_to_epd_directory/lib/python2.7/site-packages

This puts the tar.gz file into the site-packages

Then extract it using:

tar -zxvf pymodule.tar.gz

a directory named pymodule is created, cd into that module and type:

 python setup.py install 

and that should do the job.

like image 31
user2502020 Avatar answered Sep 23 '22 00:09

user2502020