Home >Backend Development >Python Tutorial >Installing pip on CentOS: A detailed tutorial giving convenience and flexibility to Python development
Full tutorial: Install pip on CentOS to provide convenience and flexibility for Python development. Specific code examples are required
Introduction: Python is a popular programming language. Has a strong ecosystem and a large number of third-party libraries. In the Python development process, pip is an important tool, which can help us easily install, upgrade and manage various Python packages. This article will introduce the detailed steps to install pip on CentOS and provide specific code examples.
1. Update the system
Before installing pip, we need to update the system first to ensure that we get the latest software packages and security patches.
Open a terminal and execute the following command:
sudo yum update -y
This will update all installed packages and dependencies.
2. Install Python
CentOS 7 comes with a Python 2.7 installation package, but we need to install the Python 3.x version to cooperate with the use of pip. Execute the following command to install Python 3:
sudo yum install -y python3
After the installation is complete, execute the following command to verify whether the Python installation is successful:
python3 --version
If the installation is successful, the version number of Python will be displayed.
3. Install pip
On CentOS, we can use the easy_install tool to install pip. Install setuptools first, then use easy_install to install pip.
Execute the following command to install setuptools:
sudo yum install -y python3-setuptools
After the installation is complete, execute the following command to install pip:
sudo easy_install -3.8 pip
After the installation is completed, execute the following command to verify whether the pip installation is successful:
pip3 --version
If the installation is successful, the version number of pip will be displayed.
4. Configure pip source
By default, pip uses foreign software sources, and the download speed may be slow. We can configure the pip source as a domestic mirror site to speed up the download speed.
Open the terminal and execute the following command:
mkdir ~/.pip
echo -e "[global]
index-url = https://pypi. tuna.tsinghua.edu.cn/simple" > ~/.pip/pip.conf
The above command will create a hidden directory named .pip and create a file named pip.conf in it file, configure the pip source as the Tsinghua University open source mirror site.
5. Use pip to install Python packages
Now we have successfully installed and configured pip. During the Python development process, we can use pip to easily install various third-party libraries.
Take installing the requests library as an example, execute the following command:
pip3 install requests
This will download and install the requests library from the source.
6. Upgrade pip
In order to obtain the latest version of pip and some new features, we can upgrade pip regularly.
Execute the following command to upgrade pip:
pip3 install --upgrade pip
This will upgrade pip to the latest version.
7. Uninstall pip
If you no longer need pip, you can uninstall it at any time.
Execute the following command to uninstall pip:
pip3 uninstall pip
After executing the above command, you will be prompted to confirm the uninstallation, enter y to confirm.
Conclusion:
Through the above steps, we can successfully install pip on CentOS and use pip to easily install and manage various Python packages. The use of pip provides convenience and flexibility for Python development, making the development process more efficient.
Summary code example:
sudo yum update -y
sudo yum install -y python3
sudo yum install -y python3-setuptools
sudo easy_install-3.8 pip
mkdir ~/.pip
echo -e "[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple" > ~/.pip/pip.conf
pip3 install requests
pip3 install --upgrade pip
pip3 uninstall pip
References:
Note: This tutorial uses CentOS 7 as an example systems, other versions of CentOS or other Linux distributions may differ slightly. Please adjust according to the actual situation.
The above is the detailed content of Installing pip on CentOS: A detailed tutorial giving convenience and flexibility to Python development. For more information, please follow other related articles on the PHP Chinese website!