Is it possible to run python bytecode files without the need of the C Python interpreter to be installed on the host OS ?
Asked
Active
Viewed 601 times
1
-
Bytecode is just code *for the interpreter*. It is not machine code that can be run directly. Note that the ``bytecode`` tag even says "the CPython interpreter runs bytecode stored in .pyc files." – MisterMiyagi Jun 29 '20 at 19:20
-
Python "bytecode" is not the result of a compilation process. It is the result of the expensive parsing process stored in an interpreter friendly binary format. – Klaus D. Jun 29 '20 at 19:21
-
@KlausD - .pyc files are a header plus a marshaled code object which has already been compiled. – tdelaney Jun 29 '20 at 20:22
-
@tdelaney Compiled in a broader meaning of the word. Not compiled as a compiler would do for example for C code. – Klaus D. Jun 29 '20 at 20:38
-
1@KlausD. - We could debate what "interpreter" means, but python compiles source into byte code and then executes the byte code in the "python virtual machine". It does what the java compiler does to java source. And pretty much what the C compiler does, except the target is byte code, not machine code. Because its dynamic it doesn't need things like C header files or external java class definitions, but its still a compiler. – tdelaney Jun 29 '20 at 20:52
-
You can use `Tools/freeze` as in [How can I create a stand-alone binary from a Python script](https://docs.python.org/3/faq/programming.html?highlight=pyc#how-can-i-create-a-stand-alone-binary-from-a-python-script) but I've never tried it myself. – tdelaney Jun 29 '20 at 20:56
1 Answers
2
No, python interpreter is required.
You can use apps such as pyinstaller to make a executable of your scripts so that all required packages and python libs including the interpreter is self contained in a single executable. It runs like any other programs so nothing else needs to be done except double click and run.
Also .pyc files require the specific version of python to run with which they are compiled so it is really not a recommended way of distributing python code if thats what you are planning.
This answer has more details: https://stackoverflow.com/a/36027342/4289062

Canute S
- 334
- 1
- 5
- 12