build a static executable program with python

T

Torsten Mohr

Hi,

i'd like to build an executable file that is linked with
a python library and executes a script via PyRun_SimpleString
or similar functions.

Is there a static library of python available, so the users
don't need to install python?


What about DLL modules, do i just need to compile them
as a static lib, link them together with my program and
call their init function?


What about python modules, can i just use a tool like
"freeze" or "py2exe" to break up the import hierarchy
and call them before my script?


Is there some more information about building a static
executable available?


Thanks for any hints,
Torsten.
 
D

David Fraser

Torsten said:
Hi,

i'd like to build an executable file that is linked with
a python library and executes a script via PyRun_SimpleString
or similar functions.

Is there a static library of python available, so the users
don't need to install python?


What about DLL modules, do i just need to compile them
as a static lib, link them together with my program and
call their init function?


What about python modules, can i just use a tool like
"freeze" or "py2exe" to break up the import hierarchy
and call them before my script?


Is there some more information about building a static
executable available?


Thanks for any hints,
Torsten.
Just have a look at py2exe, it does basically what you're asking for -
see the link to the wiki from the py2exe home page for more information...

David
 
A

Adal Chiriliuc

My app uses Python 2.4 and the Pythonwin GUI (Python MFC wrapper).
I build it as a single exe file with everything linked in it. It's
a lot smaller than all the DLL's put together.

The Python modules are also put into the file as a Win32 resource
which contains all the modules bz2 compressed. I gather the required
modules the same way as py2exe does (using modulefinder), then I
compile them to .pyc files, bundle them all together in one file with
some information (like size and name) and than bzip compress the whole
file. When the app starts it uncompresses them and init's the
PyImport_FrozenModules variable (just like in freeze).

So I only have one exe file to ship, which contains everything needed.
Right now it's size is 2 MB, but bear in mind that it contains STLport
and Crypto++ which are big libraries. It compresses down to under 1 MB.

It's not very difficult to do if you have some experience. But you do
have to tweak some Python header files (to disable for example the
normal link against python24.lib).

You are right about the DLL modules. You just compile tham as a static
lib and manually call their's their's init function, AND ALSO THE
DllMain ONE. The exe file will still export the DLL functions, but you
can disable this with some tweaks.

Hope that helps. I can guide you through the process if you wish.

i'd like to build an executable file that is linked with
a python library and executes a script via PyRun_SimpleString
or similar functions.
 
T

Torsten Mohr

Hi,

thank you very much for that detailled description.
I will try to get as far as i can with this information and
get back to you if i have any questions.


Thanks a lot,
Torsten.
 
T

Torsten Mohr

Hi Adal,

can you send me your mail address? I think the one in your
posting is a spam stopper.


Cheers,
Torsten.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top