Home  >  Article  >  Backend Development  >  Installation tutorial using pip: teach you how to specify the source for installation

Installation tutorial using pip: teach you how to specify the source for installation

PHPz
PHPzOriginal
2024-01-18 10:52:171075browse

Installation tutorial using pip: teach you how to specify the source for installation

Source installation guide: Teach you how to use pip to specify the source for installation. Specific code examples are required

Introduction:
In the process of developing and using Python, We often encounter situations where we need to install third-party libraries. As a package management tool for Python, pip can easily obtain and install various libraries from PyPI (Python Package Index). However, due to network limitations or other reasons, we may need to use a specific mirror source for installation. This article will introduce how to use pip to specify the source for installation, and provide specific code examples.

1. Understand the source of pip:
When we use the pip command to install, the default source is PyPI. However, due to network restrictions in China, we often need to use other mirror sources to replace PyPI. The following are some commonly used mirror sources:

  1. Tsinghua University: https://pypi.tuna.tsinghua.edu.cn/simple
  2. Alibaba Cloud: https://mirrors. aliyun.com/pypi/simple
  3. University of Science and Technology of China: https://pypi.mirrors.ustc.edu.cn/simple

2. Use pip to specify the source for installation:
It is very simple to install using pip to specify the source. You only need to add the -i parameter and the specified source address after the installation command. The following are the specific steps:

Step 1: Open the command line terminal (or use Anaconda Prompt).

Step 2: Use the following command to install, where <package></package> is the name of the library that needs to be installed, and <source></source> is the address of the mirror source.

pip install -i <source> <package>

For example, if we want to install the numpy library through the Tsinghua University source, we should use the following command:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple numpy

3. Sample code:
The following are some specific sample codes to demonstrate How to use pip to specify sources to install different libraries.

  1. Install numpy library:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple numpy
  1. Install requests library:
pip install -i https://mirrors.aliyun.com/pypi/simple requests
  1. Install matplotlib library:
pip install -i https://pypi.mirrors.ustc.edu.cn/simple matplotlib

4. Summary:
Through the introduction of this article, we learned how to use pip to specify the source for installation. Whether in a restricted network environment or to speed up installation, using a designated source installation library is a good choice. I hope this article will be helpful to you and allow you to use pip to install Python libraries more flexibly.

The above is the detailed content of Installation tutorial using pip: teach you how to specify the source for installation. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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