Installation#

Installing from prepackaged binaries#

Stable releases of contourpy are available from PyPI, conda-forge, and Anaconda default channels for Linux, macOS and Windows.

  1. To install from PyPI:

    $ pip install contourpy
    
  2. To install from conda-forge:

    $ conda install -c conda-forge contourpy
    
  3. To install from Anaconda default channel:

    $ conda install contourpy
    

The only compulsory runtime dependency is NumPy.

If you want to make use of one of contourpy’s utility renderers in the contourpy.util module you will also have to install either Matplotlib or Bokeh.

Installing from source#

The source code for contourpy is available from github. Either git clone it directly, or fork and git clone it from your fork, as usual.

Note

You should install contourpy from source into a new virtual environment using conda or venv for example. To use venv to create a new virtual environment in a directory called .venv/contourpy and activate it:

$ python -m venv ~/.venv/contourpy
$ . ~/.venv/contourpy/bin/activate

From the base directory of your local contourpy git repo, build and install it in editable mode using:

$ pip install -ve .

To build in debug mode, which enables assert statements in the C++ code, use the CONTOURPY_DEBUG environment variable:

$ CONTOURPY_DEBUG=1 pip install -ve .

Running tests#

To run the test suite, first ensure that the required dependencies are installed and then run the tests using pytest:

$ pip install -ve .[test]
$ pytest

It is possible to exclude certain tests. To exclude image comparison tests, for example if you do not have matplotlib installed:

$ pytest -k "not image"

To exclude threaded tests:

$ pytest -k "not threads"

Other tests are excluded by default but can be manually enabled. To include tests that generate text output:

$ pytest --runtext

but note that the output depends on the version of freetype that matplotlib is compiled against. To include tests that take a long time to run:

$ pytest --runslow

BokehRenderer tests will be run if bokeh is installed, otherwise they will be skipped.

Building the documentation#

To build the documentation:

$ pip install -ve .[docs]
$ cd docs
$ make html

Warning

If you modify some of the C++ source code and wish to ensure a completely clean build, you can first use:

$ git clean -fxd

although use this with care as it will also delete any new files that you have created that have not been added to git and are not mentioned in the .gitignore file.

Notes for contributors#

Contributors are recommended to install pre-commit hooks which will automatically run various checks whenever git commit is run. First install pre-commit using either

$ pip install pre-commit

or

$ conda install -c conda-forge pre-commit

and then install the hooks using

$ pre-commit install

The hooks will then be run on each git commit. You can manually run the hooks outside of a `git commit using

$ pre-commit run --all-files