Installing Python Modules

Key terms

·         pip is the preferred installer program. Starting with Python 3.4, it is included by default with the Python binary installers.

·         virtual environment is a semi-isolated Python environment that allows packages to be installed for use by a particular application, rather than being installed system wide.

·         venv is the standard tool for creating virtual environments, and has been part of Python since Python 3.3. Starting with Python 3.4, it defaults to installing pip into all created virtual environments.

·         virtualenv is a third party alternative (and predecessor) to venv. It allows virtual environments to be used on versions of Python prior to 3.4, which either don’t provide venv at all, or aren’t able to automatically install pip into created environments.

 

Basic usage

The standard packaging tools are all designed to be used from the command line.

The following command will install the latest version of a module and its dependencies from the Python Packaging Index:

    python -m pip install SomePackage


Normally, if a suitable module is already installed, attempting to install it again will have no effect. Upgrading existing modules must be requested explicitly:

    python -m pip install --upgrade SomePackage

Pip not installed

It is possible that pip does not get installed by default. One potential fix is:

    python -m ensurepip --default-pip 

There are also additional resources for installing pip.

Post a Comment

0 Comments