Heroku python supported versions

Heroku-22 Stack

This stack is now based on Ubuntu 22.04, compared to Ubuntu 20.04 used in the Heroku-20 stack.

The most important changes compared to Heroku-20 are:

  • The stack no longer includes a system Ruby installation. This will not affect the vast majority of users, since Ruby apps will use the Ruby installation provided by the Ruby buildpack.
  • The stack no longer includes a system Python 2 installation (accessed on Heroku-20 via the python2 command). Python 3 continues to be available via the python and python3 commands, as it was for Heroku-20.

Available software

Every stack on Heroku supports different operating system packages and language runtime versions. This support is typically confined to software that was still actively developed by the respective maintainers at the time the stack was first released.

Language runtimes

For the most accurate information on supported language runtime versions, please check the individual language pages:

Buildpack Shorthand Runtime versions
Ruby heroku/ruby Runtime versions
Node.js heroku/nodejs Runtime versions
Python heroku/python Runtime versions
Java heroku/java Runtime versions
PHP heroku/php Runtime versions
Go heroku/go Runtime versions

Operating system packages

For a full list of operating system packages available on Heroku-22, please refer to article Ubuntu Packages on Heroku Stacks.

Support period

Heroku-22 is based on Ubuntu 22.04. It will be supported through April 2027. Learn more about Heroku’s stack update policy.

Using Heroku-22

Heroku-22 is currently the default stack for newly created apps.

You can specify a stack when creating an app:

$ heroku create --stack heroku-22 

You may change the stack on an existing app; the next build performed will then use the new stack:

If you are using app.json , you should also specify the stack there to ensure that your Review Apps and Heroku CI runs use the same stack:

An existing app’s stack cannot be changed using app.json . The stack specified is only applied to newly created apps that are a Review App, a Heroku CI test run app, or an app created using a Heroku Button.

Upgrading to Heroku-22

Please refer to the stack upgrading guide to understand the procedures to follow when upgrading to a new stack.

We recommend that you monitor your application closely after migrating an app to the new stack to ensure it’s performing correctly.

Читайте также:  Индекс максимального элемента массива питон

Upgrade notes

System Ruby is no longer installed

The stack no longer includes a system Ruby installation. This will not affect the vast majority of users, since by default Ruby apps will use the Ruby installation provided by the Ruby buildpack instead.

If your app is implemented in a language other than Ruby, but relies on Ruby for scripting purposes e.g. during startup or for controlling workers, you may have to add the heroku/ruby buildpack to your app.

If your application uses Ruby and you see ruby: command not found errors, check that you haven’t accidentally been using the system-level Ruby installation; you may do so by verifying the Ruby buildpack is present in your application’s list of buildpacks using heroku buildpacks . If the heroku/ruby buildpack (or a GitHub URL equivalent) is missing, see our buildpacks documentation for how to add it. You will need to check the buildpack order carefully — the newly added Ruby buildpack may need to go prior to any other buildpacks, depending on exactly where Ruby is being used.

If after adding the Ruby buildpack, you are still seeing ruby: command not found errors from profile.d/ scripts at application boot, this is due to the fact that profile.d/ scripts are sourced in alphabetical order, and buildpack Ruby is only added to PATH once the profile.d/ruby.sh script runs. Any other profile.d/ scripts will need to have a name that sorts alphabetically after ruby.sh . Alternatively, you can move the contents of any affected profile.d/ scripts to the .profile file instead, which is guaranteed to always run after all other profile.d/* scripts.

If you are a maintainer of a buildpack that uses Ruby, you will need to either:

  1. Modify the buildpack so that it vendors Ruby as part of the build (example).
  2. Rewrite the Ruby parts of the buildpack to be shell scripts instead.
  3. Update the buildpack documentation to say end users should add the Ruby buildpack prior to the buildpack in question (they will also need to ensure minimal Gemfile / Gemfile.lock files exist, so that the Ruby buildpack passes detection).

System Python 2 is no longer installed

The stack no longer includes a system Python 2 installation (accessed on Heroku-20 via the python2 command), since Python 2 has been sunset upstream for some time.

The system Python installation is not the same as the one provided by the Python buildpack (which had previously dropped support for Python 2, starting in Heroku-20).

Читайте также:  font-size

Python 3 continues to be available via the python and python3 commands (either via system Python, or the buildpack provided Python installation), as it was for Heroku-20.

OpenSSL 3

Ubuntu 22.04 ships with OpenSSL 3.0. OpenSSL 1.1 is not available as a runtime library.

If you see OpenSSL/libssl related errors (for example libssl.so.1.1: cannot open shared object file or SSL_read: unexpected eof while reading , but there will be many other variations), you will need to update your dependencies and/or third-party buildpacks to versions that are compatible with OpenSSL 3, and ensure that dependencies or binaries you use are compiled against OpenSSL 3.

In addition, OpenSSL 3 drops default support for a number of legacy/insecure cryptographic algorithms. If you see TLS/SSL related failures connecting from your application to external services, it is likely that those servers are running outdated/insecure software or configurations, that will need to be fixed by the maintainers of those services.

The static buildpack is no longer supported

The experimental heroku-buildpack-static buildpack is not supported on Heroku-22. If your application is using that buildpack (check the output of the heroku buildpacks command for either heroku-community/static or heroku-buildpack-static ), you will need to switch to the more modern and regularly maintained Nginx buildpack instead (available via heroku-community/nginx ).

For more information, see this migration guide.

Heroku-22 Docker image

Heroku-22 is available as two Docker images:

  1. The runtime image ( heroku/heroku:22 ), which is recommended over the build image for most workloads.
  2. The build image ( heroku/heroku:22-build ), which is larger as it includes development headers and toolchains. It is only recommended for customers that need to compile source code or dependencies.

Use the following command in your Dockerfile to use Heroku-22 as your base image:

To learn more about deploying Docker images, please refer to the Heroku Container Registry and Runtime documentation.

Keep reading

Источник

Heroku Python Support

Heroku supports all popular web frameworks for Python including Django, Flask, and so on.

For a deployment tutorial that uses a sample Django app, see Getting Started on Heroku with Python.

Recognizing a Python App

Heroku automatically recognizes your app as a Python app if it includes a requirements.txt , setup.py , or Pipfile file in its root directory.

When Heroku recognizes a deployed application as a Python application, you see this build output:

$ git push heroku master -----> Python app detected 

Specifying a Python Version

By default, newly created Python apps use the python-3.11.4 runtime. You can also specify a different supported Python version.

Supported Runtimes

  • python-3.11.4 (available on all stacks; recommended)
  • python-3.10.12 (available on all stacks)
  • python-3.9.17 (available on all stacks)
  • python-3.8.17 (available on the Heroku-20 stack only)
Читайте также:  Пишем telegram bot java

Deprecated Runtimes

If you see “Requested runtime is not available for this stack” errors using one of the supported versions, check that your app is using the latest version of the Python buildpack.

Build Behavior

If your app includes a requirements.txt file, Heroku runs the following command to resolve dependencies:

$ pip install -r requirements.txt 

Database Auto-Provisioning

This section is only applicable to accounts created before May 15, 2023 or if you asked Heroku Support to enable auto-provisioning for your account.

A mini Heroku Postgres database automatically provisions on the first deploy of your app if:

  • You created your account before May 15, 2023 or if you asked Heroku Support to enable auto-provisioning for your account
  • A manage.py file exists in the root of the app source
  • Both the django and psycopg2 packages are installed

Automatic provisioning of a database also populates your app’s DATABASE_URL config var.

A Heroku Postgres database is not automatically provisioned for other Python apps, but you can easily provision one manually.

Checking the Python Buildpack Version

The Python buildpack is what transforms your Python source code into a slug that can be deployed on Heroku.

For the best results, it’s recommended that you use the latest stable version of the buildpack, rather than pinning to a tag or branch or using a fork. Otherwise, some documented features don’t work, and you don’t benefit from future bug fixes or improvements made to the buildpack.

The stable heroku/python buildpack release is also pre-installed in the build environment, so using it improves build performance compared to GitHub URLs.

To check which buildpacks are configured on your app, use the heroku buildpacks CLI command:

$ heroku buildpacks === my-example-app Buildpack URL https://github.com/heroku/heroku-buildpack-python.git 

If you see a GitHub URL like in the example or one that’s pinned to a custom branch or tag, then it’s recommended to switch to the heroku/python buildpack. heroku/python is the curated stable buildpack registry release.

To switch buildpacks, first clear the existing buildpacks set on the app using:

$ heroku buildpacks:clear Buildpacks cleared. 

Then add the Python buildpack:

$ heroku buildpacks:add heroku/python Buildpack added. 

Finally, check that the configured buildpacks are correct:

$ heroku buildpacks === my-example-app Buildpack URL heroku/python 

If you originally set multiple buildpacks on your app, you must add them in the same order as they were listed in heroku buildpacks previously. For example:

$ heroku buildpacks === my-example-app Buildpack URLs 1. heroku-community/example-buildpack 2. https://github.com/heroku/heroku-buildpack-python.git $ heroku buildpacks:clear $ heroku buildpacks:add heroku-community/example-buildpack $ heroku buildpacks:add heroku/python $ heroku buildpacks === my-example-app Buildpack URLs 1. heroku-community/example-buildpack 2. heroku/python 

Источник

Оцените статью