Controlling Complexity Using Package Managers

By Ryan Wiles

Eggs, Wheels, & More: All About Packages

Python Eggs

Eggs are a zip file based “zero installation” packaging format that was originally introduced in 2004. They are created using the setuptools project and used by setuptools’ easy_install module. Eggs are a Built Distribution that package up both code and optionally data files and metadata such as and dependencies in an easy to distribute fashion. Eggs can contain pure Python code or can include natively compiled code such as C.

Wheels

Wheels are a more recent Built Distribution created in 2012 and are defined in PEP 427. Wheels were designed to replace Eggs and also be easier to install than sdist. The pip command installs wheels.

Additional details on about the what Wheels have to look like and how to build them can be found in the Packaging and Deploying section.

What is a Package Manager

What is a Distribution

What is a Virtual Manager

What is a Sandbox

Package Managers, Distributions, Sandboxes, & Virtual Environments

easy_install

Homepage: https://setuptools.readthedocs.io/en/latest/easy_install.html

easy_install is a now deprecated package management module in the setuptools project that is used to install eggs. Its functionality has been replaced by pip and should no longer be used. It’s being included here for the sake of completeness when reading older documentation on Python.

pip

Homepage: https://pip.pypa.io/en/stable/

pip, which stands for “pip installs packages”, is managed by PyPa and is Python’s current defacto general-purpose package manager. It’s also the name of the command line tool. pip by default installs packages from PyPI

We’re going to principally use the pip command line tool for installing and managing the packages within a Python installation. pip maintains a directory containing the installed packages.

Running the pip command in a terminal with no arguments shows all of commands and options that pip accepts. A shorted example just showing the commands is shown below.

pip command options:

$ pip

Usage:   
  pip <command> [options]

Commands:
  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  list                        List installed packages.
  show                        Show information about installed packages.
  check                       Verify installed packages have compatible dependencies.
  config                      Manage local and global configuration.
  search                      Search PyPI for packages.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion.
  help                        Show help for commands.

Showing the pip version & package installation directory:

$ pip --version # If using the default Python installation
/Users/rwiles/anaconda3/bin/pip
$ pip2 --version # For Python 2 if Python was installed with Homebrew
pip 18.0 from /usr/local/lib/python2.7/site-packages/pip (python 2.7)
$ pip3 --version # For Python 3 if Python was installed with Homebrew
pip 18.0 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)

When searching for a package with pip, it will return all packages containing the search term in its name or description. If the package is already installed, it will show both the current “INSTALLED” version and the “LATEST” version as in the below example:

Searching for a package with pip:

$ pip3 search numpy
numpy (1.15.2)                        - NumPy: array processing for numbers, strings, records, and objects.
  INSTALLED: 1.14.3
  LATEST:    1.15.2
numpy-sugar (1.2.8)                   - Missing NumPy functionalities
numpy-turtle (0.1)                    - Turtle graphics with NumPy
mapchete-numpy (0.1)                  - Mapchete NumPy read/write extension
...
zmqnumpy (0.1)                        - numpy array over zmq sockets
array_to_latex (0.41)                 - Return Numpy arrays as formatted LaTeX arrays.
arrfunc (1.0)                         - Lazy evaluation to treat functions as numpy arrays.

Installing a package:

$ pip3 install mpltools
Collecting mpltools
  Downloading https://files.pythonhosted.org/packages/bd/99/5fe7ba3fb80428ec5efaf1fcf40019b8e8e4821ff62c75eaea0e6161db9e/mpltools-0.2.0.tar.gz
Requirement already satisfied: matplotlib>=1.0 in ./anaconda3/lib/python3.5/site-packages (from mpltools) (2.2.2)
...
Building wheels for collected packages: mpltools, configobj
  Running setup.py bdist_wheel for mpltools ... done
  ...
Successfully built mpltools configobj
Installing collected packages: configobj, mpltools
Successfully installed configobj-5.0.6 mpltools-0.2.0```

Upgrading an installed package:

$ pip install --upgrade numpy
Collecting numpy
  Downloading https://files.pythonhosted.org/packages/ff/77/33012e58a59c85d8a30c6e9fa54f46d6056b016d8f710d0102888f29c22a/numpy-1.15.2-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (24.4MB)
    100% |████████████████████████████████| 24.4MB 28kB/s 
Installing collected packages: numpy
  Found existing installation: numpy 1.14.3
    Uninstalling numpy-1.14.3:
      Successfully uninstalled numpy-1.14.3
Successfully installed numpy-1.15.2

Installing a specific version of a Package:

pip install numpy==1.15.2

Removing an installed package:

$ pip uninstall mpltools
Uninstalling mpltools-0.2.0:
  Would remove:
    /Users/rwiles/anaconda3/lib/python3.5/site-packages/mpltools-0.2.0.dist-info/*
    /Users/rwiles/anaconda3/lib/python3.5/site-packages/mpltools/*
Proceed (y/n)? y
  Successfully uninstalled mpltools-0.2.0

PyEnv

Homepage: https://github.com/pyenv/pyenv

“lets you easily switch between multiple versions of Python. It’s simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well.” - pyenv

Virtual Environments / Sandboxes

Virtualenv

“Virtualenv is a tool to create isolated Python environments.” https://virtualenv.pypa.io/en/stable/

Conda

Conda is a language independent cross-platform environment manager that manages a “conda” environment. Conda doesn’t install packages from PyPI, instead installing them from the official Anaconda repositories or user-shared conda packages at anaconda.org. However like many package manager, Conda allows you to specify additional channels to install packages from. Conda combines package management, virtual environment management and deployment of binary extensions in a single tool. This provides comparable functionality to using pip, virtualenv and wheel. However, pip can be installed into Conda allowing you to manage package distributions from PyPI.

Homepage: https://conda.io/docs/

Anaconda

Anaconda is a distribution (curated selection of pre-build packages) that is built on top of Conda which packages together many Data Science libraries to provide a popular Python Data Science platform with over 1000 open-source Data Science libraries. In addition Anaconda has bundled integrated tools such as Jupyter Lab/Notebook, RStudio, Spyder, and an option to install VS Code.

Homepage: https://www.anaconda.com

Anaconda Distribution Tutorial

References

© 2018 Ryan Wiles