I am not very familiar with how the underlying internals of Python implementations really work, but it is known that basically there are two steps in executing a Python program: the code is first transformed into the bytecode (the well-known .pyc files), which is then executed by the VM.
One of the big unresolved issues in Python world is distribution of applications, and there are many approaches, each with its own advantages and disadvantages: wrapping them up in self-contained environments like Docker containers, packing them together with the interpreter into a single binary (e.g. PyOxidizer) etc.
I’ve recently been thinking about one approach, but have no idea if it would be possible, in theory or in practice. Once the code is compiled into bytecode, all it requires is the virtual machine; it there a way to extract just the VM and use it to run the app without the interpreter? If it is, it might be possible to package the bytecode and the VM in an executable binary with a much smaller footprint that including the whole interpreter and the bytecode…
I’m mainly looking to understand if that is possible in theory (i.e. whether there are any conceptual issues in Python as a language that would prevent that separation), and if it is, whether it can be attempted with the existing implementations (primarily CPython). And, of course, if the answer to both is “yes”, has that been attempted in any way?
Or, of course, the whole idea might be completely bonkers for some obvious reasons that I have missed… I’d appreciate any comments. Thank you!