How to specify source installation with pip

尊渡假赌尊渡假赌尊渡假赌
Release: 2023-12-19 11:28:20
Original
2585 people have browsed it

Pip specified source installation has three methods: "specify the source in the command line", "configure the default source" and "use environment variables": 1. Use the --index-url or -i parameter in the command line Specify the source; 2. Create a pip.conf file in the pip folder in the user directory and add the URL address of the default source; 3. Set the "PIP_INDEX_URL" environment variable to specify the URL of the source.

How to specify source installation with pip

# Operating system for this tutorial: Windows 10 system, Dell G3 computer.

To specify a specific source to install a Python package, you can use the --index-url or -i parameter to specify the URL of the source. The following are several common ways to specify the source:

  1. Specify the source in the command line:
pip install --index-url <源的URL> <包名>
Copy after login

or

pip install -i <源的URL> <包名>
Copy after login

For example, to use Tsinghua University To install the requests package from the university's mirror source, you can execute the following command:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple requests
Copy after login
  1. Configure the default source:
    If you often use a specific source for installation, you can set it as the default source. Create a pip.conf file in the pip folder under your user directory (if it doesn't exist) and add the following:
[global]
index-url = <源的URL>
Copy after login

Replace with the one you want to use The URL of the source.

For example, on Windows, you can create a pip.ini file in the C:\Users\your username\pip directory and add the following content:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
Copy after login

In this way, you Will default to using the specified source for all pip installations.

  1. Using environment variables:
    Another method is to specify the source by setting an environment variable. The PIP_INDEX_URL environment variable can be set to specify the URL of the source.

    In the command line, use the following syntax to set environment variables and install packages:

PIP_INDEX_URL=<源的URL> pip install <包名>
Copy after login

For example, to use the mirror source of Tsinghua University to install the requests package, you can Execute the following command:

PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple pip install requests
Copy after login

One of these methods should allow you to specify a specific source to install Python packages from. Keep in mind that when using unofficial sources, make sure the source is trustworthy and you still need to be careful with installed packages.

The above is the detailed content of How to specify source installation with pip. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!