HomeDocs
DocsCommunityTestimonialsUsersGitHubTwitterBlogJobsTermsPrivacyCookies
TermsPrivacyCookies
Hey! These docs are for version 2.13, which is no longer officially supported. Click here for the latest version, 2.17!


Example Python repository

See [here](🔗) for examples of Pants's Python functionality.

See [here](🔗) for Django-specific examples.

Enable the Python [backend](🔗) like this:



Pants use [`python_source`](🔗) and [`python_test`](🔗) targets to know which Python files to run on and to set any metadata.

To reduce boilerplate, the [`python_sources`](🔗) target generates a `python_source` target for each file in its `sources` field, and [`python_tests`](🔗) generates a `python_test` target for each file in its `sources` field.



You can generate these targets by running [`./pants tailor ::`](🔗).



macOS users: you may need to change interpreter search paths

By default, Pants will look at both your `$PATH` and—if you use Pyenv—your `$(pyenv root)/versions` folder when discovering Python interpreters. Your `$PATH` likely includes the system Pythons at `/usr/bin/python` and `/usr/bin/python3`, which are known to have many issues like failing to install some dependencies.

Pants will prefer new Python versions, like 3.6.10 over 3.6.3. Because macOS system Pythons are usually very old, they will usually be ignored.

However, if you run into issues, you can set the `search_paths` option in the `[python-bootstrap]` scope:



See [here](🔗) for more information.