1

Question

Is runtime.txt the official Python way to specify the python version to use? I suppose it is not what Python supports out of the box and I believe the version of Python runtime depends on the binary package management of each system (apt, brew, yum), unless explicitly download from https://www.python.org/downloads/.

However, if there is a known mechanism to switch Python version, please advise.

Background

There are several articles, mostly from Heiroku related, about runtime.txt to be specific with which version of Python to run.

mon
  • 13,270
  • 8
  • 74
  • 138
  • 1
    It's mainly for web application hosts to detect the runtime of your application/program so that when you spin up your app in those services (i.e. IBM cloud in your post, Heroku, Docker, etc), they spin up the correct environment to run your code. – TYZ Apr 29 '20 at 01:55

1 Answers1

0

Review

Local

To get a list of all installed Python versions available through the launcher, run:

py --list

Get sure that version that you want to use presents here.

Then you can crete a virtual environment with specific version like:

py -3.9 -m venv env/place/you/want/to/save/to

or, with virtualenv:

virtualenv --python=python3.9 env/place/you/want/to/save/to

If you want to specify path to your python:

virtualenv --python=/usr/bin/python3.9 env/place/you/want/to/save/to

Instead 3.9 insert version you need.

https://stackoverflow.com/a/67259741/13363187

Server

You can watch your python version with pip:

env/Scripts/activate
pip -V

and specify runtime version at runtime.txt:

python-3.9.10

that version will be used at server automatically (for example, Heroku server support it).