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

6

31

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.

Tympanist answered 20/6, 2013 at 14:43 Comment(4)
have you considered using virtualenv ?Oller
yes but I would like to know how to do this without using a virtualenv.Tympanist
this might help:#2915971Oller
You're ment to replace $PREFIX_PATH with whatever install directory you'd like to have.Amphibious
S
53

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.

Schumacher answered 2/5, 2014 at 19:7 Comment(3)
error: must supply either home or prefix/exec-prefix -- not bothStanding
I think pip install X --user is the shortcutGenius
Readable command: pip install --target any/path/i/like package_nameMemorial
T
5

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.

Tympanist answered 20/6, 2013 at 16:35 Comment(0)
G
-1

Instead, you could use a copy of pip that has been installed into your EPD installation.

$ path-to-EPD/bin/enpkg pip # Or simply enpkg pip, if EPD is on your PATH. 
$ path-to-EPD/bin/pip install <package-name>
Gluey answered 20/6, 2013 at 23:0 Comment(0)
W
-1

This worked for me on Ubuntu Gnome 17.04. Installing PyMySQL to specific dir:

sudo pip install PyMySQL -t /home/mahmoud/app
Wanton answered 21/10, 2017 at 6:10 Comment(1)
sudo pip install should never be used.Xyloid
A
-1

This answer worked in windows OS
Short answer: To install package to the specific folder using -t option ex:pip install packageX -t lib/, then add this folder to PYTHONPAHT

Long answer:

  1. install virtualenv to .env folder

  2. pip install with -t option, example install to lib folder of my project (named 3)
    (.env) d:\tmp\3>pip install packageX -t lib/

  3. show list of packages :

    (.env) d:\tmp\3>pip list
    Package    Version
    ---------- ----------
    pip        18.1
    setuptools 40.6.3
    ...
  1. Not see your package ? open command-prompt as administrator right and set PYTHONPATH

enter image description here

  1. now new command prompt and activate env will see your packages enter image description here
Advice answered 14/1, 2019 at 7:31 Comment(0)
B
-1

You can use this code to install you package to a specific path.

pip install [package name] --target /path/to
Bonnard answered 7/1, 2020 at 0:50 Comment(2)
Please consider adding a comment to what your code does. A single code line without any feedback is a very low quality answerLabrie
This is the same as the top answer from years ago. -t is just shorthand for --target.Xyloid

© 2022 - 2024 — McMap. All rights reserved.