473,734 Members | 2,331 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.

Jul 18 '05 #1
4 4722
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_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.

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
Jul 18 '05 #2
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:
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.


Jul 18 '05 #3
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.

Jul 18 '05 #4
Hi Adal,

can you send me your mail address? I think the one in your
posting is a spam stopper.
Cheers,
Torsten.
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
22715
by: Alexandre Gillet | last post by:
Hi, I am trying to build a python interpreter that is static link. My python interpreter was build on RedHat 8.0 using gcc 2.3 and GLIBC 2.3 When running on other linux flavor that still have GLIBC 2.2, the interpreter won't start. (error message: /lib/libc.so.6: version `GLIBC_2.3' not found (required by /mgl/python/i86Linux2/bin/python2.3) Is there a way to build a static python interpreter using gcc 2.3 that can run on any machine...
3
7309
by: mudd | last post by:
How do I build Python so that I get static libraries instead of dynamic libraries (e.g. build/lib.solaris-2.8-sun4u-2.3/math.so)? John
1
2095
by: | last post by:
Hello, I tried to build Python 2.4.1 on a Reliant Unix system. Just after the python executable program has been built, I get the following error: ==== begin make output === CC -W1 -Blargedynsym -o python \ Modules/python.o \ libpython2.4.a -lresolv -lsocket -lnsl -ldl -lm
0
1518
by: Adam Tomjack | last post by:
I'm trying to embed Python 2.3.5 into a C++ application on Windows XP. When I build my app with debug symbols and link to a debug build of Python, then my program seems to crash most (but not all) of the time. Sometimes it crashes on startup, and sometimes at exit, sometimes not at all. I haven't seen it crash with non-debug builds of my app and Python. The release build runs my Python test code just fine. When the debug build doesn't...
1
1440
by: Grzegorz Dostatni | last post by:
Cheers. I am trying to create a single executable that contains my program. Due to legal issues I was unable to use a dynamically linked python executable. Over the last couple of weeks I managed to create a statically linked python executable that contains everything we need (Qt, ssl, bz2, etc). My final step should be to use that executable and freeze all the python code inside it. Problem is, when I try that - it tries to create a...
10
2216
by: Larry Hastings | last post by:
I'm an indie shareware Windows game developer. In indie shareware game development, download size is terribly important; conventional wisdom holds that--even today--your download should be 5MB or less. I'd like to use Python in my games. However, python24.dll is 1.86MB, and zips down to 877k. I can't afford to devote 1/6 of my download to just the scripting interpreter; I've got music, and textures, and my own crappy code to ship. ...
1
1577
by: mrstephengross | last post by:
I'm working on building python 2.4.2 with the mingw compiler (on cygwin). It runs into problems with Modules/posixmodule.c, because the mingw compiler does *not* provide complex process management functionality. I can exclude posixmodule.c from the python build process, but gcc still fails when it tries to link together the python executable: (Error message follows) ================================= gcc -mno-cygwin ...
2
1757
by: keepyourstupidspam | last post by:
Hi, I have a strange build problem. I am building an exe, this exe links to a number of static libraries maybe 20 in all and all are built from my code. I am using the gmake build system and the MS visual studio 2003 compiler and linker. When I perform a completely clean build the binary builds fine to a
1
2177
by: Will Ware | last post by:
I am trying to freeze a static executable. I built a static Python executable this way: ./configure --disable-shared --prefix=/usr/local make make install Even that didn't give me a really static executable, though: $ ldd /usr/local/bin/python linux-gate.so.1 => (0xffffe000) libpthread.so.0 => /lib/tls/libpthread.so.0 (0xb7f44000) libdl.so.2 => /lib/libdl.so.2 (0xb7f40000)
0
8780
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9246
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9186
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8190
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6742
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6035
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4553
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4816
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2733
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.