fabtools.python

Python environments and packages

This module includes tools for using virtual environments and installing packages using pip.

Virtual environments

fabtools.python.virtualenv(*args, **kwds)[source]

Context manager to activate an existing Python virtual environment.

from fabric.api import run
from fabtools.python import virtualenv

with virtualenv('/path/to/virtualenv'):
    run('python -V')

Installing pip

fabtools.python.is_pip_installed(version=None, pip_cmd='pip')[source]

Check if pip is installed.

fabtools.python.install_pip(python_cmd='python', use_sudo=True)[source]

Install the latest version of pip, using the given Python interpreter.

import fabtools

if not fabtools.python.is_pip_installed():
    fabtools.python.install_pip()

Note

pip is automatically installed inside a virtualenv, so there is no need to install it yourself in this case.

Installing packages

fabtools.python.is_installed(package, pip_cmd='pip')[source]

Check if a Python package is installed (using pip).

Package names are case insensitive.

Example:

from fabtools.python import virtualenv
import fabtools

with virtualenv('/path/to/venv'):
    fabtools.python.install('Flask')
    assert fabtools.python.is_installed('flask')
fabtools.python.install(packages, upgrade=False, use_mirrors=False, use_sudo=False, user=None, download_cache=None, quiet=False, pip_cmd='pip')[source]

Install Python package(s) using pip.

Package names are case insensitive.

Examples:

import fabtools

# Install a single package
fabtools.python.install('package', use_sudo=True)

# Install a list of packages
fabtools.python.install(['pkg1', 'pkg2'], use_sudo=True)
fabtools.python.install_requirements(filename, upgrade=False, use_mirrors=False, use_sudo=False, user=None, download_cache=None, quiet=False, pip_cmd='pip')[source]

Install Python packages from a pip requirements file.

import fabtools

fabtools.python.install_requirements('project/requirements.txt')
Read the Docs v: 0.17.0
Versions
latest
0.17.0
0.16.0
0.15.0
0.14.0
0.13.0
0.12.0
0.11.0
Downloads
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.