Python plugin

The Python plugin can be used for Python projects where you would want to do any of the following things:

  • Import Python modules with a requirements.txt file.

  • Build a Python project that has a or pyproject.toml file.

  • Install packages using pip.


This plugin uses the common plugin keywords as well as those for sources.

Additionally, this plugin provides the plugin-specific keywords defined in the following sections.


Type: list of strings

List of paths to requirements files.


Type: list of strings

List of paths to constraint files.


Type: list

A list of dependencies to install from PyPI. If needed, pip, setuptools and wheel can be upgraded here.

Environment variables

This plugin also sets environment variables in the build environment. These are defined in the following sections.


Default value: python3

The interpreter binary to search for in PATH.


Default value: (empty string)

Additional arguments for venv.


Since none of the bases that are available for rocks contain a default Python installation, including a Python interpreter in Rockcraft projects is mandatory. The plugin also requires the venv module to create the virtual environment where Python packages are installed at build time.

The easiest way to do this is to include the python3-venv package in the stage-packages of the part that uses the Python plugin. This will pull in the default Python interpreter for the build-base, like Python 3.10 for Ubuntu 22.04. However, other versions can be used by explicitly declaring them - here’s an example that uses python3.12-venv from the Deadsnakes ppa:

  - type: apt
    ppa: deadsnakes/ppa
    priority: always

    plugin: python
    source: .
    stage-packages: [python3.12-venv]

How it works

During the build step, the plugin performs the following actions:

  • It creates a virtual environment directly into the ${CRAFT_PART_INSTALL} directory.

  • It uses pip to install the required Python packages as configured in the python-requirements, python-constraints and python-packages keywords.

  • If the source contains a or pyproject.toml file, those files are used to install the dependencies specified by the package itself.