Executable & 3.8 vs 3.9

I create an executable using venv and > pyinstaller main.py --onefile
I create it on Ubuntu 22.04 using python 3.9.

Should I expect that executable to run on any version of Ubuntu, for example, can I run it on 20.04 with python 3.8 as its default installation?

I didn’t realize that I might have to run on Ubuntu 20.04 (its default installation of python 3.8 is missing libraries I require). I’m looking for a way to get around upgrading the 20.04 box from python 3.8 → 3.9 and breaking stuff, or from having to upgrade from Ubuntu 20.04 → 22.04.

My hope was that venv might package everything needed in order to run on Ubuntu 20.04 inside the executable, but that doesn’t seem to be the case. My original understanding was that use of venv would allow me to use any version of python that I wanted by isolating that version of python inside the virtual environment and preventing a conflict with the python installation at the OS level. But, now I believe that I was mistaken.

Am I in trouble?

You can install a newer version of python for the user, rather than updating the system python. In general it’s best not to use that python installation or install packages into it, because Ubuntu is relying on it for managing the system.

A virtual env will isolate the packages you’ve installed, but it doesn’t use a different python executable. But you should be able to install a newer version alongside the system installation.

2 Likes

From PyInstaller documentation:

PyInstaller reads a Python script written by you. It analyzes your code to discover every other module and library your script needs in order to execute. Then it collects copies of all those files – including the active Python interpreter! – and puts them with your script in a single folder, or optionally in a single executable file.
[…]
You distribute the bundle as a folder or file to other people, and they can execute your program. To your users, the app is self-contained. They do not need to install any particular version of Python or any modules. They do not need to have Python installed at all.

1 Like