Specifying a Python Runtime
Last updated 08 January 2018
Table of Contents
This document describes the general behavior of Heroku as it relates to the recognition and execution of Python applications. For framework specific tutorials, please see Deploying Python and Django Apps. To get started, see Getting Started with Python on Heroku.
The Heroku Python Support will be applied to applications only when the application has a
Pipfile in the root directory. Even if an application has no module dependencies, it should include an empty
Pipfile to document that your app has no dependencies.
Supported Python runtimes
Heroku’s Python support extends to the latest stable release from the Python 3.x and Python 2.x series.
Today, this support extends to these specific runtimes:
Selecting a runtime
Newly created Python applications default to the Python 3.6.3 runtime.
You can specify an arbitrary version of Python to be used to run your application. This functionality is enabled by the presence of a
$ cat runtime.txt python-2.7.14
Note: If you specify a different Python runtime than a previous build, your application’s build cache will be purged, and all dependencies will be re–installed.
Alternatively, you can also specify a Python version in a
Pipfile.lock, if you are using Pipenv. Add the following to your
[requires] python_version = "2.7"
Or, more specifically:
[requires] python_full_version = "2.7.14"
$ pipenv lock to generate the appropriate
Pipfile.lock, and push it to Heroku.
A number of additional, unsupported runtimes are available. However, we only endorse and support the use of Python 3.6.2 and 2.7.14.
PyPy is a fantastic Python runtime, and can vastly increase the speed of many Python applications. However, it is not without its own quirks. You are encouraged to use PyPy only if you understand PyPy.
The following libraries are used by the platform for managing and running Python applications and cannot be specified.
- Setuptools 23.1.0: Python packaging tools.
- Pip 9.0.1: Application dependency resolution.
If your application declares these dependencies in a
Pipfile, unexpected behavior may occur.
The following command is run on your app to resolve dependencies:
$ pip install -r requirements.txt
Or, if you’re using Pipenv:
$ pipenv install --system
.heroku directory is cached between pushes to speed up package installation.
Pure Python applications, such as headless processes and evented web frameworks like Twisted, are fully supported on Cedar.
When a deployed application is recognized as a pure Python application, Heroku responds with
-----> Python app detected.
$ git push heroku master -----> Python app detected
No add-ons are automatically provisioned if a pure Python application is detected. If you need a SQL database for your app, add one explicitly:
$ heroku addons:create heroku-postgresql:dev
web process types created if a Python application is detected.
All versions of Django are fully supported on Cedar.
A dev database add-on is provisioned automatically for Django applications. This populates the
DATABASE_URL environment variable.