Install a Python Package into a Different Directory Using Pip

Install a Python package into a different directory using pip?

Use:

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

You might also want to use --ignore-installed to force all dependencies to be reinstalled using this new prefix. You can use --install-option to multiple times to add any of the options you can use with python setup.py install (--prefix is probably what you want, but there are a bunch more options you could use).

Install Test Python Package in Different directory Using Pip

Try doing it this way instead

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

install python package at current directory

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 .

PIP installing packages to wrong instance/directory of python

Try and create the virtual environment within the project and then you can pip install your package around your project.

cd into your project directory and do;

for Mac OX or Linux

python3 -m venv <name of your env>
source <name of your env>/bin/activate
pip install your package name

or for windows;

python -m venv <name of your env>
.\<name of your env>\Scripts\activate
pip install your package name

It's not always good to install package globally as it will be conflicting with other packages.

Installing Python packages from local file system folder to virtualenv with pip

I am pretty sure that what you are looking for is called --find-links option.

You can do

pip install mypackage --no-index --find-links file:///srv/pkg/mypackage

Installing pip packages in different directory does not work

Update: When I wrote this answer pipenv was not available. If you having the same problem, I strongly recommend considering using it.

If you have installed Python using brew you need to add a setup.cfg file (source) in your project-dir with the following content:

[install]
prefix=

That will resolve the problem. Alternatively, you can use virtualenv or even better docker.

How to install python package in a specific directory

If you put the module files in a directory, for example external_modules/, and then use sys.path.insert(0, 'external_modules') you can include the module as it would be an internal module.

You would have to call sys.path.insert before the first import of the module.
Example: If you placed a "module.pyd" in external_modules/ and want to include it with import module, then place the sys.path.insert before.

The sys.path.insert() is an app-wide call, so you have to call it only once. It would be the best to place it in the main file, before any other imports (except import sys of course).



Related Topics



Leave a reply



Submit