Compiling Python into native code?

Possible duplicate:
Is it possible to compile Python for machine code?

Is it possible to compile Python code (plus its dependencies, as well as an interpreter library) into a single Windows executable with the natural (with nothing connected with it) from the Python file? (Like, for example, how the GNU compiler for Java compiles Java into a native (humongous) executable that contains everything in true machine code.)

If so, how do I do this?

(In particular, py2exe does not do what I want - it includes libraries inside a separate ZIP file and includes the interpreter as a separate DLL.)

Note 1:

To emphasize, I am not asking for a "self-extracting archive", an "executable packer", or any other way of "tricking" by linking files inside exe - I'm looking for something that really converts Python to its own executable, for example, what GCJ does for java.

Note 2:

Only if this is not possible:

Is it possible, at least, to generate a single executable file from Python code that contains an interpreter included with all library dependencies, so that to execute the executable file you do not need to self-extract to the target disk before launching it?

In this case, the “compilation” requirement is weakened: it doesn’t matter whether the code is really compiled into machine code (it can simply be inserted as a text resource into the target executable file), but the result should nevertheless be the only exe file [and nothing else], which can work autonomously, especially without the need to unpack / install anything on the target disk before starting.

+7
source share
2 answers

Shed Skin can compile Python in C ++, but only a limited subset. Some aspects of Python are very difficult to compile using native code.

+7
source

The short answer is no, and it will go in almost any language: any program you write will depend on some external libraries, even if it is only Windows system DLLs.

If you wrote a C program and compiled it using the Microsoft compiler, you still need the C runtime libraries. Most likely, they will already be on most systems, but this is not guaranteed. Similarly, even if you manage to compile the Python C interpreter statically linked to its libraries, you still need to get the C runtime.

I suspect you are really asking if you can compile a single .exe file, which depends only on the libraries that you have a reasonable expectation of already installed. So, it all depends on what you are ready to consider part of the base system? Can you assume that the .NET Framework 4 or Silverlight is installed? If so, you can look at IronPython.

Similarly, pypy can be created either using the Visual Studio toolbar or using MinGW, but I am sure that in both cases you will need some external libraries at run time.

+1
source

All Articles