Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install a Python package into a different directory using pip?

Tags:

python

pip

I know the obvious answer is to use virtualenv and virtualenvwrapper, but for various reasons I can't/don't want to do that.

So how do I modify the command

pip install package_name 

to make pip install the package somewhere other than the default site-packages?

like image 280
Monika Sulik Avatar asked May 26 '10 17:05

Monika Sulik


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 change the directory in 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.

Can you install Python packages using pip?

The pip command has options for installing, upgrading and deleting packages, and can be run from the Windows command line. By default, pip installs packages located in the Python Package Index (PyPI), but can also install from other indexes.


1 Answers

The --target switch is the thing you're looking for:

pip install --target=d:\somewhere\other\than\the\default package_name 

But you still need to add d:\somewhere\other\than\the\default to PYTHONPATH to actually use them from that location.

-t, --target <dir>
Install packages into <dir>. By default this will not replace existing files/folders in <dir>.
Use --upgrade to replace existing packages in <dir> with new versions.


Upgrade pip if target switch is not available:

On Linux or OS X:

pip install -U pip 

On Windows (this works around an issue):

python -m pip install -U pip 
like image 125
Janusz Skonieczny Avatar answered Sep 30 '22 11:09

Janusz Skonieczny