I have an application written in python 2.7 . In my app I want to give users the ability to compile a python source file (i.e py to pyc).
The builtin compile function does this but the output file is only compatible with python 2.7.
What I want is to compile the file to a range of different python versions (specifically python 2.5 , 2.6 & 2.7 )
I know that one way to approach this problem is re-write my application in each of those versions and just use the inbuilt compile function, but I do not want to do this.
I am open to all suggestions including writing a C extension, embedding python etc...
EDIT
The application which I am writing is a tool which allows to inject/modify arbitrary code inside a pyinstaller exe.
Now you may be knowing that pyinstaller actually puts compiled python source files within the exe. My app just extracts these embedded pyc files, decompiles them, allows the user to modify them, and then rebuild the exe.
Since the exe can be from a different python version, so I need the functionality to compile the decompiled output to that version.
Here is a screenshot of that app.

I solved my own problem in a different approach.
Now, my main app is written in python 2.7. I wrote 2 dll each of which had a python interpreter embedded. Within one I embedded python 2.6 and within other python 2.5.
Each of these two dlls uses the Python C API to compile a script given as an argument to the respective python version.
Now, from my main app (written in python 2.7) , I used ctypes to call the exported functions from these two dlls. The script to compile was passed as an argument.
Using this approach I was able to compile a given script to any of the 3 python versions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With