Master Python Package Management: distutils, setuptools, pip & More
This article explains the relationships among Python's package management tools—including distutils, setuptools, distribute, easy_install, and pip—provides practical examples, command references, and guidance on choosing the right tool for your projects.
Python Package Management Tools
Python offers many mature packages that can be installed to extend programs, typically sourced from the Python Package Index (PyPI). Managing these packages involves tools such as distutils, setuptools, distribute, easy_install, and pip.
distutils
distutils is part of the Python standard library and provides a simple way to package and install modules via setup.py. Example setup.py:
from distutils.core import setup
setup(
name='fooBar',
version='1.0',
author='Will',
author_email='[email protected]',
url='http://www.cnblogs.com/wilber2013/',
py_modules=['foo', 'bar'],
)Running python setup.py sdist creates a zip package that can be installed with python setup.py install.
setuptools and distribute
setuptools enhances distutils by adding dependency management and supports the .egg format. distribute was a fork of setuptools that has since merged back, so they are effectively the same.
easy_install
After installing setuptools/distribute, easy_install can be used to install packages directly from PyPI, install local archives, or install .egg files. Example commands:
Install from PyPI: easy_install package Install a local archive: easy_install package.tgz Install an .egg file: easy_install package.egg Use easy_install --help for more options.
pip
pip is now the most popular Python package manager and is considered the replacement for easy_install, though it still relies on setuptools for many functions. pip addresses easy_install’s shortcomings by providing atomic operations, uninstall support, and better dependency handling.
Common pip commands:
Install a package: pip install SomePackage Uninstall a package: pip uninstall SomePackage List installed packages: pip list Show outdated packages: pip list --outdated Upgrade a package: pip install --upgrade SomePackage Show package files: pip show --files SomePackage Install a specific version: pip install SomePackage==1.0.4 Export requirements: pip freeze > requirements.txt Install from requirements file:
pip install -r requirements.txtSummary
The article clarifies the relationships among Python's package management tools—distutils, setuptools, distribute, easy_install, and pip—helping readers understand how to choose and use them effectively. It does not cover how to create and publish a Python package.
Signed-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.
