When faced with the need to install a Python package in a directory other than the default site-packages, users commonly resort to virtualenv and virtualenvwrapper. However, for certain use cases, that approach may not be feasible or preferred.
Pip's --target Switch
To modify the installation directory in Pip, utilize the --target switch. For instance:
pip install --target d:\somewhere\other\than\the\default package_name
This command will install package_name in the specified d:somewhereotherthanthedefault directory.
Adding Directory to PYTHONPATH
Note that while the package is installed in the custom directory, you will need to add the path to PYTHONPATH to enable accessing the installed modules from that location.
Upgrade Pip for --target Availability
Depending on your Pip version, you may not find the --target switch available. To resolve this, upgrade Pip:
pip install -U pip
python -m pip install -U pip
The above is the detailed content of How to Install Python Packages to a Custom Directory Without Using Virtualenv?. For more information, please follow other related articles on the PHP Chinese website!