Home  >  Article  >  Backend Development  >  Install pip on CentOS and easily install Python extension library, detailed tutorial

Install pip on CentOS and easily install Python extension library, detailed tutorial

PHPz
PHPzOriginal
2024-01-18 09:03:07865browse

Install pip on CentOS and easily install Python extension library, detailed tutorial

Teach you step by step how to install pip on CentOS and easily install the Python extension library

Introduction: When using Python for development, we often need to use some third-party Extension libraries to simplify development work. As a Python package management tool, pip can easily help us install and manage these extension libraries. This article will introduce how to install pip on the CentOS operating system and install the Python extension library through pip.

Step One: Install Python and pip

  1. First, we need to make sure that Python is installed. Open a terminal and run the following command to check whether Python has been installed:

    python --version

    If the version number of Python is displayed, Python has been successfully installed. If it is not installed, you can install Python through the following command:

    sudo yum install python
  2. Install pip:

    sudo yum install epel-release
    sudo yum install python-pip

    After the installation is complete, you can use the following command to check whether pip is installed successfully:

    pip --version

    If the version number of pip is displayed, it means that pip has been successfully installed.

Step 2: Configure pip

  1. During the installation process, pip will automatically install a configuration file. We can find the location of the file with the following command:

    pip config list

    Find the path to "Configuration File" and then open the file with a text editor.

  2. Add the following content in the configuration file to specify the source of pip:

    [global]
    index-url = https://pypi.python.org/simple
    trusted-host = pypi.python.org

    Save and close the configuration file.

Step 3: Use pip to install the Python extension library

Through pip, we can easily install the Python extension library. Take installing the commonly used requests library as an example:

pip install requests

In this way, the requests library can be successfully installed. If you need to install other Python extension libraries, just replace "requests" with the corresponding library name.

When using pip to install the Python extension library, you can specify the version to be installed:

pip install requests==2.23.0

With the == symbol, we can accurately specify the version number of the library to be installed.

If you need to uninstall an installed Python extension library, you can use the following command:

pip uninstall requests

In summary, we can install pip on CentOS and configure it correctly, using pip easily installs and manages Python extension libraries. This will greatly improve our development efficiency. When writing code, we only need to focus on business logic without worrying about library installation and dependencies. Hope this article is helpful to you!

The above is the detailed content of Install pip on CentOS and easily install Python extension library, detailed tutorial. 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