In the current state of packaging in Python, one needs a set of tools to easily manipulate the packaging ecosystem. There are two tools in particular that are extremely handy in the current ecosystem. There is a third tool, Virtual Environments, that will be discussed later in this documentation that will assist in isolating a packaging ecosystem from the global one. The combination of these tools will help to find, install and uninstall packages.
Distribute is a collection of enhancements to the Python standard library module: distutils (for Python 2.3.5 and up on most platforms; 64-bit platforms require a minimum of Python 2.4) that allows you to more easily build and distribute Python packages, especially ones that have dependencies on other packages.
Distribute was created because the Setuptools package is no longer maintained. Third-party packages will likely require setuptools, which is provided by the Distribute package. Therefore, anytime time a packages depends on the Setuptools package, Distribute will step in to say it already provides the setuptools module.
Distribute can be installed using the distribute_setup.py script. It can also be installed using easy_install, pip, the source tarball, or the egg distribution. distribute_setup.py is the simplest and preferred way to install Distribute on all systems.
Download distribute_setup.py and execute it, using the Python interpreter of your choice.
From the *nix shell you can do:
$ wget http://python-distribute.org/distribute_setup.py $ python distribute_setup.py
For those on Mac OS X, you can use curl -O <url> instead of wget.
The development version of Distribute can be found at: http://bitbucket.org/tarek/distribute/
Pip is an installer for Python packages written by Ian Bicking. It can install packages, list installed packages, upgrade packages and uninstall packages.
The pip application is a replacement for easy_install. It uses mostly the same techniques for finding packages, so packages that were made easy_installable should be pip-installable as well.
??? Pip requirements
The Pip installer can be installed using the source tarball or using easy_install. The source tarball is the recommended method of installation.
The latest version of the source tarball can be obtained from PyPI:
$ wget http://pypi.python.org/packages/source/p/pip/pip-0.7.2.tar.gz $ tar xzf pip-0.7.2.tar.gz $ cd pip-0.7.2 $ python setup.py install
Or the easy_install application can be used:
$ easy_install pip
The pip application is now installed.
Let’s install the Markdown package:
$ pip install Markdown
Markdown is now installed; you can import and use it:
$ python -c "import markdown; print markdown.markdown('**Excellent**')"
To list installed packages and versions, use the freeze command:
$ pip freeze Markdown==2.0.3 wsgiref==0.1.2
The wsgiref package is a part of the Python standard library. Currently it is the only standard library package that includes package metadata, so it is the only standard library package whose presence pip reports.
You can also give pip a version specifier for a package using one or more of ==, >=, >, <, <=:
$ pip install 'Markdown<2.0'
This will find your current installation of Markdown 2.0.3, automatically uninstall it, and install Markdown 1.7 (the latest version in the 1.x series) in its place. You can even combine version specifiers with a comma:
$ pip install 'Markdown>2.0,<2.0.3'
If you want to upgrade a package to its most recent available version, use the -U or --upgrade flag:
$ pip install -U Markdown
Now let’s uninstall Markdown:
$ pip uninstall Markdown
After showing you which files/directories will be removed and requesting confirmation, pip will uninstall everything installed by the Markdown package.
Pip inside a Virtual Environment will only uninstall packages installed within that virtual environment. For instance, if you try to pip uninstall wsgiref it will refuse, because the reference is within the global Python’s standard library.