Sam Hooke

Configure Python package to install dependencies only for specific combinations of Python version and platform

PEP 508 introduced environment markers which let you specify conditions for whether a package should be installed. These can be used inside the install_requires or setup_requires argument in, or within the requirements.txt.

The most simple example is:

argparse; python_version < "2.7"

This would only install argparse if the Python version is lower than 2.7.

However PEP 508 details many more enivonment markers, and specifies the grammar for combining these. For example:

baz; python_version >= "3.6" and platform_system == "Linux"

This would only install baz if the Python version is greater than or equal to 3.6, and the system is Linux.

These are rough notes from whatever I was working on, interested in or thinking about at the time. They vary greatly in quality and length, but prove useful to me, and hopefully to you too!

← Previous: Python click: allow user to retry input upon validation failure
Next: Migrating from Tastypie to Django REST Framework →