build a static executable program with python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Torsten Mohr

    #1

    build a static executable program with python

    Hi,

    i'd like to build an executable file that is linked with
    a python library and executes a script via PyRun_SimpleStr ing
    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.

  • David Fraser

    #2
    Re: build a static executable program with python

    Torsten Mohr wrote:[color=blue]
    > Hi,
    >
    > i'd like to build an executable file that is linked with
    > a python library and executes a script via PyRun_SimpleStr ing
    > 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.
    >[/color]
    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

    Comment

    • Adal Chiriliuc

      #3
      Re: build a static executable program with python

      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_Frozen Modules 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:[color=blue]
      > Hi,[/color]
      [color=blue]
      > i'd like to build an executable file that is linked with
      > a python library and executes a script via PyRun_SimpleStr ing
      > or similar functions.[/color]
      [color=blue]
      > Is there a static library of python available, so the users
      > don't need to install python?[/color]
      [color=blue]
      > 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?[/color]

      [color=blue]
      > 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?[/color]

      [color=blue]
      > Is there some more information about building a static
      > executable available?[/color]

      [color=blue]
      > Thanks for any hints,
      > Torsten.[/color]



      Comment

      • Torsten Mohr

        #4
        Re: build a static executable program with python

        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.

        Comment

        • Torsten Mohr

          #5
          Re: build a static executable program with python

          Hi Adal,

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


          Cheers,
          Torsten.

          Comment

          Working...