build a static executable program with python

Discussion in 'Python' started by Torsten Mohr, Dec 30, 2004.

  1. Torsten Mohr

    Torsten Mohr Guest

    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.
    Torsten Mohr, Dec 30, 2004
    #1
    1. Advertising

  2. Torsten Mohr

    David Fraser Guest

    Torsten Mohr wrote:
    > 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
    David Fraser, Dec 30, 2004
    #2
    1. Advertising

  3. 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.

    On Thursday, December 30, 2004 Torsten Mohr wrote:
    > 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.
    Adal Chiriliuc, Dec 30, 2004
    #3
  4. Torsten Mohr

    Torsten Mohr Guest

    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.
    Torsten Mohr, Dec 30, 2004
    #4
  5. Torsten Mohr

    Torsten Mohr Guest

    Hi Adal,

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


    Cheers,
    Torsten.
    Torsten Mohr, Dec 30, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alexandre Gillet

    build a static python executable on linux?

    Alexandre Gillet, Sep 29, 2003, in forum: Python
    Replies:
    6
    Views:
    998
    Alexandre Gillet
    Sep 30, 2003
  2. Replies:
    15
    Views:
    483
    Dave Thompson
    Aug 21, 2006
  3. pratap
    Replies:
    20
    Views:
    755
    Flash Gordon
    Mar 7, 2007
  4. Jason Cavett
    Replies:
    8
    Views:
    616
    Sanjay
    May 16, 2007
  5. Replies:
    0
    Views:
    437
Loading...

Share This Page