fabtools.require.python

Python environments and packages

This module provides high-level tools for using Python virtual environments and installing Python packages using the pip installer.

See also

fabtools.python

Virtual environments

fabtools.require.python.virtualenv(directory, system_site_packages=False, venv_python=None, use_sudo=False, user=None, clear=False, prompt=None, virtualenv_cmd='virtualenv', pip_cmd='pip', python_cmd='python')[source]

Require a Python virtual environment.

from fabtools import require

require.python.virtualenv('/path/to/venv')

Installing packages

fabtools.require.python.package(pkg_name, url=None, pip_cmd='pip', python_cmd='python', allow_external=False, allow_unverified=False, **kwargs)[source]

Require a Python package.

If the package is not installed, it will be installed using the pip installer.

Package names are case insensitive.

Starting with version 1.5, pip no longer scrapes insecure external urls by default and no longer installs externally hosted files by default. Use allow_external=True or allow_unverified=True to change these behaviours.

from fabtools.python import virtualenv
from fabtools import require

# Install package system-wide (not recommended)
require.python.package('foo', use_sudo=True)

# Install package in an existing virtual environment
with virtualenv('/path/to/venv'):
    require.python.package('bar')
fabtools.require.python.packages(pkg_list, pip_cmd='pip', python_cmd='python', allow_external=None, allow_unverified=None, **kwargs)[source]

Require several Python packages.

Package names are case insensitive.

Starting with version 1.5, pip no longer scrapes insecure external urls by default and no longer installs externally hosted files by default. Use allow_external=['foo', 'bar'] or allow_unverified=['bar', 'baz'] to change these behaviours for specific packages.

fabtools.require.python.requirements(filename, pip_cmd='pip', python_cmd='python', allow_external=None, allow_unverified=None, **kwargs)[source]

Require Python packages from a pip requirements file.

Starting with version 1.5, pip no longer scrapes insecure external urls by default and no longer installs externally hosted files by default. Use allow_external=['foo', 'bar'] or allow_unverified=['bar', 'baz'] to change these behaviours for specific packages.

from fabtools.python import virtualenv
from fabtools import require

# Install requirements in an existing virtual environment
with virtualenv('/path/to/venv'):
    require.python.requirements('requirements.txt')
fabtools.require.python.pip(version='1.5', pip_cmd='pip', python_cmd='python')[source]

Require pip to be installed.

If pip is not installed, or if a version older than version is installed, the latest version will be installed.

fabtools.require.python.setuptools(version='0.7', python_cmd='python')[source]

Require setuptools to be installed.

If setuptools is not installed, or if a version older than version is installed, the latest version will be installed.