10 Practical pip Commands and Tips for Managing Python Packages
This article introduces ten useful pip techniques—including installation, upgrading, version-specific installs, uninstalling, checking for updates, handling compatibility, using domestic mirrors, downloading without installing, and batch installing from requirements files—to help Python developers efficiently manage their packages.
For most Python users, pip is a familiar tool, but many are unaware of its full capabilities; this guide presents ten practical pip tips that simplify package management and enhance workflow.
Installation
Since Python 3.4 (and Python 2.7.9), pip is bundled with the official installer, and it is also included in virtual environments created by virtualenv or pyvenv.
If pip is missing, run the following command in a configured Python environment: py -m ensurepip --upgrade Alternatively, download get-pip.py from https://bootstrap.pypa.io/get-pip.py and execute python get-pip.py.
How to Use
After installation, typing pip in the command line displays the usage help.
Upgrade pip
To upgrade pip itself, run: pip install --upgrade pip or
pip install -U pipInstall a Specific Package Version
Install a package with a particular version using: pip install package-name For example, to install matplotlib version 3.4.1:
pip install matplotlib==3.4.1Uninstall or Update a Package
To uninstall a package: pip uninstall package_name To update a package:
pip install --upgrade package_name
# or
pip install -U package_nameShow Package Information
Display detailed information about a package:
pip show -f requestsList Outdated Packages
Find packages that have newer versions available:
pip list -oCheck for Compatibility Issues
Check for dependency conflicts for a specific package or for all installed packages:
pip check package_name
pip checkInstall Using Domestic Mirrors
If download speed is slow, specify a Chinese mirror, e.g.:
pip install -i https://pypi.douban.com/simple/ package_nameCommon mirrors include Tsinghua, Alibaba Cloud, USTC, HUST, SDUT, and Douban.
Download Without Installing
To download a package to a specific directory without installing: pip download package_name -d "path/to/dir" Example:
pip download requests -d "."Batch Install Packages
Generate a requirements.txt file with currently installed packages: pip freeze > requirements.txt Install all packages listed in the file:
pip install -r requirements.txtSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
