10 Essential pip Tricks Every Python Developer Should Know
This guide presents ten practical pip tips for Python developers, covering installation, upgrades, package installation, batch requirements, uninstallation, dependency freezing, information lookup, upgrade checks, compatibility verification, and local downloading, each illustrated with clear commands and examples.
It is well known that pip can install, update, and uninstall third‑party Python libraries conveniently. Many have used pip for a long time but are unaware of its useful features. The following tips aim to help you get more out of Python pip.
Python pip
Python is popular not only because it is easy to learn but also because it has thousands of libraries. These libraries act as ready‑made tools that can be used once installed, handling many problems without reinventing the wheel, and many have become powerful enough for enterprise‑grade applications.
Libraries are stored in the Python Package Index ( PyPi) repository. pip serves as the manager that retrieves packages from PyPi and installs them into your Python environment, also handling updates, searches, and uninstalls.
Below are ten common pip tips for reference.
1. Install pip
Since Python 3.4, pip is bundled with Python, so no separate installation is needed.
If your Python version lacks pip, you can install it using one of two methods:
Run easy_install pip in the command line.
Download the pip installer from the official site, extract it to your Python scripts directory, and execute python setup.py install.
pip download page: https://pypi.org/project/pip/#files
For Python 3.4 or earlier, upgrade to the latest stable version to avoid technical debt.
2. Upgrade pip
If your pip version is outdated, upgrade it with:
$ pip install --upgrade pip
# or
$ pip install -U pip $ pip install -U pip
Looking in indexes: https://pypi.python.org/simple
Requirement already satisfied: pip in ./test/lib/python3.8/site-packages (21.1.1)
Collecting pip
Using cached pip-22.0.4-py3-none-any.whl (2.1 MB)
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 21.1.1
Uninstalling pip-21.1.1:
Successfully uninstalled pip-21.1.1
Successfully installed pip-22.0.43. Install packages
Use pip install package_name to install a third‑party library.
Specify a version with pip install package_name==1.1.2. For example:
pip install matplotlib==3.4.14. Batch install libraries
When a project requires many libraries, install them all with a requirements file: pip install -r requirements.txt The file format looks like:
# This is a comment
# Specify a diffrent index
-i http://dist.repoze.org/zope2/2.10/simple
# Package with versions
tensorflow==2.3.1
uvicorn==0.12.2
fastapi==0.63.0
pkg1
pkg2
pkg3>=1.0,<=2.0
# It is possible to refer to specific local distribution paths.
./downloads/numpy-1.9.2-cp34-none-win32.whl
# It is possible to refer to other requirement files or constraints files.
-r other-requirements.txt
-c constraints.txt
# It is possible to specify requirements as plain names.
pytest
pytest-cov
beautifulsoup45. Uninstall and upgrade packages
Uninstall a package with: $ pip uninstall package_name Upgrade a package with: $ pip install --upgrade package_name or
$ pip install -U package_name6. Freeze pip dependencies
To list all installed packages or generate a requirements file, use:
# List packages
$ pip freeze
docutils==0.11
Jinja2==2.7.2
MarkupSafe==0.19
Pygments==1.6
Sphinx==1.2.2
# Generate requirements.txt file
$ pip freeze > requirements.txtUse -l/--local to list only non‑global packages.
7. Show package information
Display detailed info with:
$ pip show -f pyyaml
Name: PyYAML
Version: 5.4.1
Summary: YAML parser and emitter for Python
Home-page: https://pyyaml.org/
Author: Kirill Simonov
Author-email: [email protected]
License: MIT
Location: /private/tmp/test/lib/python3.8/site-packages
Requires:
Required-by: awscli
Files:
PyYAML-5.4.1.dist-info/INSTALLER
PyYAML-5.4.1.dist-info/LICENSE
PyYAML-5.4.1.dist-info/METADATA
PyYAML-5.4.1.dist-info/RECORD
PyYAML-5.4.1.dist-info/WHEEL
PyYAML-5.4.1.dist-info/top_level.txt
...8. List outdated packages
Find packages that need upgrading:
$ pip list -o
Package Version Latest Type
---------- ------- ------ -----
docutils 0.15.2 0.18.1 wheel
PyYAML 5.4.1 6.0 wheel
rsa 4.7.2 4.8 wheel
setuptools 56.0.0 62.1.0 wheel9. Check compatibility issues
Verify installed packages for dependency conflicts:
$ pip check awscli
No broken requirements found.Running pip check without a package name checks all packages:
$ pip check
pyramid 1.5.2 requires WebOb, which is not installed.10. Download packages locally
Save a package as a whl file to a specific directory:
$ pip download PyYAML -d "/tmp/"
Looking in indexes: https://pypi.python.org/simple
Collecting PyYAML
Downloading PyYAML-6.0-cp38-cp38-macosx_10_9_x86_64.whl (192 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 192.2/192.2 KB 4.7 MB/s eta 0:00:00
Saved ./PyYAML-6.0-cp38-cp38-macosx_10_9_x86_64.whl
Successfully downloaded PyYAML
$ ls /tmp/PyYAML-6.0-cp38-cp38-macosx_10_9_x86_64.whl
/tmp/PyYAML-6.0-cp38-cp38-macosx_10_9_x86_64.whlSigned-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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
