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.

pipthis is done for you on install. And Python automatically does this when running the code anyway, provided there is write access at import time.compile()function does not produce.pycfiles. You can use thecompileallmodule to have Python produce those files for a whole directory or individual files instead. Just usepython-2.5 -m compileall /path/to/projectto do so with the Python 2.5 interpreter, for example.pyinstallerinstalls code with a specific Python version. There is no need to precompile there.compilefunction.