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
Understanding Inplace=True in Pandas
Python: Justifying Numpy Array
What Does the "At" (@) Symbol Do in Python
Pip Install from Git Repo Branch
Prevent Scientific Notation in Matplotlib.Pyplot
How to Uninstall Python 2.7 on a MAC Os X 10.6.4
How to Properly Determine the Current Script Directory
Converting Unix Timestamp String to Readable Date
How to Convert All Strings in a List of Lists to Integers
How to Get the Source Code of a Python Function
"Pip Install Unroll": "Python Setup.Py Egg_Info" Failed With Error Code 1
How to Print a Single Backslash
Using Global Variables Between Files
Matplotlib/Seaborn: First and Last Row Cut in Half of Heatmap Plot
How to Read a Text File into a String Variable and Strip Newlines
How to Pass a String into Subprocess.Popen (Using the Stdin Argument)