Learn how to install Python libraries using domestic sources: a simple guide for beginners

PHPz
Release: 2024-01-17 09:35:06
Original
1316 people have browsed it

Learn how to install Python libraries using domestic sources: a simple guide for beginners

In the daily Python programming process, various third-party libraries are often used. Pip is the most commonly used package management tool for Python. By using it to install and upgrade Python packages, you can make Python programming more efficient and easier. However, due to the differences between domestic and foreign network environments, you may feel confused when using pip to install the Python library. This article will introduce you to some pip tips for installing Python libraries from domestic sources that even novices can learn, and provide specific code examples.

  1. Modify pip configuration file

When using the pip command, it downloads the library from foreign sources (https://pypi.python.org/simple/) by default. Therefore, when we access this source in China, the download speed may be slow or even impossible to download due to the network environment. Therefore, we can change the default source by modifying pip's configuration file to quickly download and install Python libraries. The specific operations are as follows:

1.1 Open the pip configuration file

Enter the following command in the command line to open the pip configuration file:

$ sudo vi ~/.pip/pip.conf
Copy after login

If the pip directory does not exist, you need to first Create the pip directory:

$ mkdir -p ~/.pip && cd ~/.pip
Copy after login

1.2 Modify the configuration file content

Modify the default source of pip to a domestic source. The specific operations are as follows:

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

If you want to use other domestic sources , you can also replace the above address with other domestic source addresses.

  1. Specify the source when using pip

If we don’t want to modify the default configuration of pip, we can also speed up the download by manually specifying the source when using pip to install the Python library. The specific operations are as follows:

2.1 Specify the source when installing the Python library

When using pip to install the Python library, add -i or --index- The url parameter specifies the source from which to download the Python library. For example:

$ pip install requests -i https://pypi.tuna.tsinghua.edu.cn/simple
Copy after login

2.2 Specify the source when upgrading the Python library

When upgrading the Python library using pip, by adding -i or --index-url Parameter, specify the source from which to upgrade the Python library. For example:

$ pip install --upgrade requests -i https://pypi.tuna.tsinghua.edu.cn/simple
Copy after login
  1. Use domestic source visualization tools

If you still don’t want to modify the pip configuration file and specify the source through command line operations, we can use some third parties visualization tools. These tools allow us to easily switch domestic sources to download and install Python libraries faster. Two tools are introduced below:

3.1 pipwin

pipwin is a visual tool on the Windows platform, which can easily install third-party libraries of Python. It uses domestic sources, so Python libraries can be downloaded and installed quickly. The specific operations are as follows:

3.1.1 Install pipwin:

$ pip install pipwin
Copy after login

3.1.2 Install the Python library

Enter the following command on the command line to install the Python library:

$ pipwin install <package_name>
Copy after login

Among them, <package_name></package_name> refers to the name of the Python library to be installed.

3.2 Anaconda

Anaconda is a Python scientific computing and data analysis platform, and it is also a commonly used Python distribution in China. Its installation package has many third-party libraries for scientific computing and data analysis built into it, and you can easily manage and install Python libraries through the Anaconda Navigator tool.

In any case, you can quickly install and update Python libraries by replacing the default configuration or using a specified source. At the same time, using visual tools can also make it easier for us to install and manage Python libraries. Please choose the method that best suits your needs.

The above is the detailed content of Learn how to install Python libraries using domestic sources: a simple guide for beginners. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!