Home > Backend Development > Python Tutorial > Analyze the settings and usage steps of pip domestic mirror source

Analyze the settings and usage steps of pip domestic mirror source

WBOY
Release: 2024-01-17 08:29:16
Original
1692 people have browsed it

Analyze the settings and usage steps of pip domestic mirror source

Detailed explanation of the configuration and use of pip domestic sources

Introduction:
With the popularity of Python and the continuous expansion of its application scope, pip has become the most important thing for Python One of the package management tools. However, in the process of using pip to download Python packages in China, due to the limitations of the network environment, problems such as slow download speeds and connection timeouts often occur. In order to solve this problem, some excellent pip domestic sources have appeared in China. This article will introduce the configuration and use of pip domestic sources in detail, and provide specific code examples.

1. Selection of pip domestic sources
There are many excellent pip domestic sources to choose from in China, among which the more commonly used and stable ones are Tsinghua University, Alibaba Cloud, University of Science and Technology of China, etc. These domestic sources will mirror the packages in the official pip source to provide faster download speeds.

2. Method to configure pip domestic source
1. Use command line configuration
Execute the following command in the command line:

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
Copy after login

Among them, https://pypi.tuna .tsinghua.edu.cn/simple is the pip mirror source of Tsinghua University. You can also replace it with the address of another domestic source.

2. Use configuration file configuration
You can create a configuration file pip.conf with the following content:

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

Then put the file into the .pip folder in the user directory ( It is ~/.pip under Linux and C:Users{username}pip under Windows), and this configuration can be automatically enabled.

3. Use pip to download packages from domestic sources
The method of using pip to download packages from domestic sources is basically the same as using official sources, except that when executing the command, the package will be downloaded from domestic sources.

  1. Installation package
    Use the command line to execute the following command to install the package:

    pip install package_name
    Copy after login

    For example, install the requests package:

    pip install requests
    Copy after login
  2. Upgrade package
    Use the command line to execute the following command to upgrade the package:

    pip install --upgrade package_name
    Copy after login

    For example, upgrade the requests package:

    pip install --upgrade requests
    Copy after login
  3. Uninstall the package
    Use Execute the following command on the command line to uninstall the package:

    pip uninstall package_name
    Copy after login

    For example, uninstall the requests package:

    pip uninstall requests
    Copy after login
  4. Search for the package
    You can use the command line to execute the following command to search for the package :

    pip search keyword
    Copy after login

    For example, search for packages related to requests:

    pip search requests
    Copy after login

    The above is the basic method of using pip to download packages from domestic sources.

4. Other ways to use domestic sources

  1. Use domestic sources to download a specific version of the package
    You can use the command line to execute the following command To download a specific version of the package:

    pip install package_name==package_version
    Copy after login

    For example, to install the 2.22.0 version of the requests package:

    pip install requests==2.22.0
    Copy after login
  2. Use domestic sources to download the development version of the package
    You can Use the command line to execute the following command to download the development version of the package:

    pip install --pre package_name
    Copy after login

    For example, install the development version of requests:

    pip install --pre requests
    Copy after login
  3. Use domestic sources to download all of an index page Package
    You can use the command line to execute the following command to download all packages on the index page:

    pip download -r requirements.txt
    Copy after login

    Among them, requirements.txt is the index page that contains all packages.

    Conclusion:
    By configuring and using pip domestic sources, we can solve the problem of downloading Python packages in China and improve development efficiency. In actual development, it is recommended to choose stable and fast domestic sources and flexibly configure and use them according to your own needs. I hope this article will help you in configuring and using pip domestic sources.

    Article word count: 758 words

    The above is the detailed content of Analyze the settings and usage steps of pip domestic mirror source. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template