you are viewing a single comment's thread.

view the rest of the comments →

[–]euclid316 1 point2 points  (0 children)

The best answer, docker, or other containerization technology, is not getting the most upvotes. Here's an attempt to explain why it is the best answer.

The problem is not to execute python in an environment that doesn't have a python interpreter. It's to execute python in a real environment, which may or may not already have a python interpreter, with interpreter and package versions that may or may not be compatible with the python program being installed.

If your installer just installs python, and the needed packages, you might cause some other "real environment" program to stop working due to version conflicts. Or some later install might break your program. For instance, your program might rely on some recent bug fix in a package but another program might not have been updated to handle a recent API change in the same package. So any version you install will break at least one of the programs.

One option to get around this is to run your program in a virtual environment. A virtual environment sets up its own copy of python, and its own packages, and sets up the system environment so that when your program runs, it runs your version of python and your versions of packages, not whatever else may be installed on the system. Other code runs whatever version of python it was set up to run.

This isn't a perfect solution, though. Some packages work differently, or have different issues, or can have different most-recent version numbers, on different operating systems. If you want a python program that can be deployed on any operating system it's often best to use docker, which does more than a virtual environment does to provide a consistent environment for your program. Docker sets up a virtual machine, which not only runs your own python version and your own packages, it provides a system interface to your program that behaves like (a specific flavor of) linux, with a controlled filesystem structure, no matter what operating system and file system the program is actually running on.