Installing Python Packages in Non-Default Directories with Pip
Pip is a popular package installer for Python, but by default it installs packages in the site-packages directory. What if you want to install packages in a different location?
For those who cannot or prefer not to use virtualenv, there is an alternative method using Pip's --target switch. This switch allows you to specify the target directory for package installation:
pip install --target [directory_path] [package_name]
This will install the package in the specified directory instead of the default site-packages. However, to actually use the packages from this location, you need to add the target directory to PYTHONPATH.
Example:
pip install --target d:\somewhere\other\than\the\default package_name
Note: Ensure that the target directory exists before you run the pip command.
If the target switch is not available, you may need to upgrade pip using the following commands:
pip install -U pip
python -m pip install -U pip
Once pip is upgraded, you should be able to use the target switch to install packages in a different directory.
The above is the detailed content of How Can I Install Python Packages to a Non-Default Directory Using Pip?. For more information, please follow other related articles on the PHP Chinese website!