SoFunction
Updated on 2025-04-25

The Python package management tool is the installation and use of pip commands.

1. Introduction to pip

pip is a package management tool for Python, and its full name is "Pip Installs Packages". It is one of the most important tools in the Python ecosystem for installing and managing Python third-party libraries. Since Python versions 3.4 and 2.7.9, pip has been installed as a standard component with Python.

2. Installation of pip

1. Check if pip is installed

Enter the following command in the command line to check if pip is installed:

pip --version

or

pip3 --version

If the version information is displayed, it means it has been installed; if it is not installed, it can be installed as follows.

2. Install pip

Method 1: By installing

Download script:

curl / -o 

Run the installation script:

python 

Method 2: Install through the system package manager (Linux)

Ubuntu/Debian:

sudo apt-get install python3-pip

CentOS/RHEL:

sudo yum install python3-pip

3. Basic use of pip

Installation package

pip install package_name

For example, install the requests library:

pip install requests

Install a specific version

pip install package_name==version_number

For example, install Django version 2.2:

pip install django==2.2

Upgrade package

pip install --upgrade package_name

Uninstall the package

pip uninstall package_name

View installed packages

pip list

View package details

pip show package_name

Search Package

pip search "query"

Note: Starting from pip 20.3, the search command has been removed, and it is recommended to directly access the PyPI website for search.

4. Advanced usage

1. From installation

pip install -r 

2. Generate

pip freeze > 

3. Use domestic mirror source to accelerate

Domestic users can use the following mirror sources to speed up downloads:

  • Alibaba Cloud: /pypi/simple/
  • Tsinghua University: /simple/
  • University of Science and Technology of China: /simple/

Temporary use:

pip install -i /pypi/simple/ package_name

Permanent configuration:

pip config set -url /pypi/simple/

4. Create a virtual environment and install the package

python -m venv myenv      # Create a virtual environmentsource myenv/bin/activate # Activate the virtual environment (Linux/Mac)myenv\Scripts\activate    # Activate the virtual environment (Windows)pip install package_name  # Install packages in a virtual environment

5. Frequently Asked Questions

Permissions issue: On Linux/Mac, if you encounter permission errors, you can try:

pip install --user package_name

Version conflict: Isolate dependencies from different projects using a virtual environment

Installation failed: Try to update pip:

pip install --upgrade pip

Caching issue: Clear the pip cache:

pip cache purge

6. Best Practices

Always work in a virtual environment to avoid polluting the global Python environment

Use log project dependencies

Regularly update dependency packages for security patches and new features

Fixed dependency versions in production to avoid compatibility issues caused by accidental updates

Conclusion

pip is an indispensable tool for Python developers. Mastering its use can greatly improve development efficiency. Through the introduction of this article, I believe you have a comprehensive understanding of PIP. In actual development, using these commands flexibly will help you better manage Python project dependencies.

This is the article about the installation and use of pip commands, a powerful Python package management tool, which is introduced here. For more related content on the installation and use of pip commands, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!