Home >Backend Development >Python Tutorial >Detailed explanation of the steps to install Python library through Tsinghua mirror
Tsinghua Mirror Tutorial: How to install the Python library through Tsinghua Mirror, specific code examples are required
Introduction:
In Python development, third-party libraries are often needed to expand your functionality. However, due to limitations of the network environment, sometimes we cannot install the required libraries directly from official sources. At this time, Tsinghua Mirror becomes a good choice. This article will introduce how to use the Tsinghua mirror to install the Python library and demonstrate it through specific code examples.
1. What is Tsinghua Mirror?
Tsinghua Mirror is a set of domestic public software mirror sources developed by Tsinghua University. This mirror source provides downloads of many common open source software, frameworks and libraries, including Python, Java, Node.js, etc. By using Tsinghua mirrors, we can speed up software installation and improve development efficiency. In Python development, we can install the required libraries by specifying the Tsinghua mirror source.
2. Steps to install Python library using Tsinghua mirror
The following takes the installation of one of the most commonly used Python libraries - the requests library as an example to introduce how to install the Python library through Tsinghua mirror.
Execute the following command in the command line window to install:
python -m ensurepip --default-pip
Set the Tsinghua mirror source
Execute the following command in the command line window to set Tsinghua mirror source:
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
Install the requests library
Next, we can use the Tsinghua mirror to install the requests library. Execute the following command in the command line window:
pip install requests
After the installation is complete, we can use the requests library in our Python script.
Verify the installation result
Enter the following code in Python interactive mode:
import requests print(requests.__version__)
If the version number of the requests library is output, the installation is successful.
3. Tsinghua mirror source for other commonly used software
In addition to the Python library, Tsinghua mirror source also provides downloads of other commonly used software. Commonly used Tsinghua image sources and their setting commands are as follows:
Node.js
npm config set registry https://registry.npm.taobao.org
Java
in the ~/.bashrc file Add the following environment variables:
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export JAVA_HOME=/usr/local/jdk export PATH=$PATH:$JAVA_HOME/bin export JAVA_OPTS="-Xms1024m -Xmx1024m -XX:PermSize=256M -XX:MaxPermSize=1024M"
Ruby
gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/ gem sources -u
By using the Tsinghua mirror source, we can install faster Required Python libraries to improve development efficiency. This article introduces the steps to install the Python library using Tsinghua mirror and gives specific code examples. In addition to the Python library, we can also use the Tsinghua image to install other commonly used software. I hope this article will be helpful for installing Python libraries using Tsinghua images.
The above is the detailed content of Detailed explanation of the steps to install Python library through Tsinghua mirror. For more information, please follow other related articles on the PHP Chinese website!