How to Specify the Python Runtime Version in Heroku



Heroku


In this article, we show how to specify the Python runtime version in heroku.

The Python runtime version is the version of Python that heroku is using to execute the Python code in your project.

So in order to specify which Python runtime version you want to use, what you have to do is create a text file named runtime.txt.

In this runtime.txt file, you specify the version of Python that you want to use.

This runtime.txt file must include all three version number components (major, minor, and patch). The runtime.txt file is case sensitive adn must not include spaces. If this format is not followed, the app will fail to deploy.

So for example, if you want to run a Python runtime version of 3.7.1, the following would be in the runtime.txt file, shown below.



Again, make sure that there are no spaces after the declaration.

Also, it is best to save the file in the ANSI format, as ANSI does not add extra spaces to the text.

Make sure to place this runtime.txt file in the root directory of your project, the same directory that contains the requirements.txt file.

Now when you run this code, when you run, git push heroku master, it will update the version of Python. Depending on the pip installations that you have, it may change it to a version that is capable to the Python version you are updating to, so that everything is compatible with each other and so that your project will still work.

Also, remember that when you update to a different version of Python, make sure that it is one of the supported runtimes that heroku uses. This can be found at the following link: Supported runtimes.

And this is how to specify the Python runtime version in Heroku.


Related Resources

How to Randomly Select From or Shuffle a List in Python



HTML Comment Box is loading comments...