473,624 Members | 2,252 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

crossplatform py2exe - would it be useful?

I'm currently working on a new version of py2exe, which will require
Python 2.3 and later, because it uses the zipimport mechanism.

Since py2exe is a distutils extension, and since C compilers are
commonly available on most platforms except Windows, it would be fairly
easy to let py2exe generate a C source file installing this import hook,
and let distutils' C compiler build an executable file from this.

Would this be useful, or would I be wasting my time, since McMillan
installer, cx_freeze, and tools/freeze already do it?

At the end of this post you'll find excerpts from the readme file, which
is currently the only documentation available.

Thomas

The readme file:

A new and improved py2exe for Python 2.3
=============== =============== ==========

Uses the zipimport mechanism, so it requires Python 2.3 or later. The
zipimport mechanism is able to handle the early imports of the
warnings and also the encodings module which is done by Python.

Creates a single directory, which must be deployed completely.

(Most of this is based on ideas of Mark Hammond:) Can create any
number of console and gui executables in this directory, plus
optionally a windows service exe, plus optionally an exe and dll com
server. The com servers can expose one or more com object classes.

All pure Python files are contained in a single zip archive, which is
shared by all the executables. The zip archive may also be used by
programs embedding Python. Since extension modules cannot be imported
from zipfiles, a simple pure Python loader is included in the zipfile
which loads the extension from the file system (without requiring that
the directory is in sys.path).

It would be nice if the executables could be run with only a single
sys.path entry containing the absolute filename of the zipfile, but it
seems for dll com servers the executable's directory is also
needed. The absolute filenames are constructed at runtime from the
directory containing the executable, and the zipfile name specified at
build time.

The way has changed how build targets are specified in the setup
script. py2exe installs it own Distribution subclass, which enables
additional keyword arguments to the setup function:

console = [...] # list of scripts to convert into console executables
windows = [...] # list of scripts to convert into gui executables
com_servers = [...] # list of fully qualified class names to build into the exe com server
service = [...] # list of fully qualified class names to build into a service executable
zipfile = "xxx.zip" # filename of the zipfile containing the pure Python modules

All of the above arguments are optional. The zipfile name defaults to
'library.zip'.
Jul 18 '05 #1
20 3683
Hi Thomas;

I've tried Freeze before, but I'm hooked on py2exe because it's so
SIMPLE and flexible, and handles all the weird cases automatically.. .
For those of us that aren't C gurus, anything that makes the process
easier is welcome.

To clarify your proposal, would you simply build the executable using
the same setup.py script on other platforms too, or would you have to
do more manual steps?

Thanks for the great work so far... py2exe ROCKS! q:]

Kevin.
Thomas Heller <th*****@python .net> wrote in message news:<pt******* ***@python.net> ...
I'm currently working on a new version of py2exe, which will require
Python 2.3 and later, because it uses the zipimport mechanism.

Since py2exe is a distutils extension, and since C compilers are
commonly available on most platforms except Windows, it would be fairly
easy to let py2exe generate a C source file installing this import hook,
and let distutils' C compiler build an executable file from this.

Would this be useful, or would I be wasting my time, since McMillan
installer, cx_freeze, and tools/freeze already do it?

At the end of this post you'll find excerpts from the readme file, which
is currently the only documentation available.

Thomas

The readme file:

A new and improved py2exe for Python 2.3
=============== =============== ==========

Uses the zipimport mechanism, so it requires Python 2.3 or later. The
zipimport mechanism is able to handle the early imports of the
warnings and also the encodings module which is done by Python.

Creates a single directory, which must be deployed completely.

(Most of this is based on ideas of Mark Hammond:) Can create any
number of console and gui executables in this directory, plus
optionally a windows service exe, plus optionally an exe and dll com
server. The com servers can expose one or more com object classes.

All pure Python files are contained in a single zip archive, which is
shared by all the executables. The zip archive may also be used by
programs embedding Python. Since extension modules cannot be imported
from zipfiles, a simple pure Python loader is included in the zipfile
which loads the extension from the file system (without requiring that
the directory is in sys.path).

It would be nice if the executables could be run with only a single
sys.path entry containing the absolute filename of the zipfile, but it
seems for dll com servers the executable's directory is also
needed. The absolute filenames are constructed at runtime from the
directory containing the executable, and the zipfile name specified at
build time.

The way has changed how build targets are specified in the setup
script. py2exe installs it own Distribution subclass, which enables
additional keyword arguments to the setup function:

console = [...] # list of scripts to convert into console executables
windows = [...] # list of scripts to convert into gui executables
com_servers = [...] # list of fully qualified class names to build into the exe com server
service = [...] # list of fully qualified class names to build into a service executable
zipfile = "xxx.zip" # filename of the zipfile containing the pure Python modules

All of the above arguments are optional. The zipfile name defaults to
'library.zip'.

Jul 18 '05 #2
Thomas Heller wrote:
I'm currently working on a new version of py2exe, which will require
Python 2.3 and later, because it uses the zipimport mechanism.

Since py2exe is a distutils extension, and since C compilers are
commonly available on most platforms except Windows, it would be fairly
easy to let py2exe generate a C source file installing this import hook,
and let distutils' C compiler build an executable file from this.

Would this be useful, or would I be wasting my time, since McMillan
installer, cx_freeze, and tools/freeze already do it?


I think it would be a WONDERFUL idea: py2exe is the simplest to use
of all the tools you mention, and it would save a lot of ink^H^H^H pixels,
each time I point people to it, to be able to omit the blurb about "if
you're interested in deploying to Windows platform only, then"...:-).
Alex

Jul 18 '05 #3
On Wed, Aug 06, 2003 at 08:36:20PM +0200, Thomas Heller wrote:
I'm currently working on a new version of py2exe, which will require
Python 2.3 and later, because it uses the zipimport mechanism.


Now that zipimport is part of Python the code required for bootstrapping
a py2exe runtime is just:

myscript -c "import sys; sys.path.insert (0, sys.executable) ; import foo"

This reduces the difference between the custom interpreter supplied with
py2exe and the standard interpreter to just a few lines of C.

The obvious question is - why not go all the way and put this little
hook into the standard Python distribution? This way py2exe could be a
platform-independent pure Python application. In fact, py2exe wouldn't
actually be necessary because anyone could create a zip file manually and
append it to the executable but it's more convenient to have a tool that
automates the process and finds the required dependencies.

Oren

Jul 18 '05 #4
Oren Tirosh wrote:
On Wed, Aug 06, 2003 at 08:36:20PM +0200, Thomas Heller wrote:
I'm currently working on a new version of py2exe, which will require
Python 2.3 and later, because it uses the zipimport mechanism.


Now that zipimport is part of Python the code required for bootstrapping
a py2exe runtime is just:

myscript -c "import sys; sys.path.insert (0, sys.executable) ; import foo"

This reduces the difference between the custom interpreter supplied with
py2exe and the standard interpreter to just a few lines of C.

The obvious question is - why not go all the way and put this little
hook into the standard Python distribution? This way py2exe could be a
platform-independent pure Python application. In fact, py2exe wouldn't
actually be necessary because anyone could create a zip file manually and
append it to the executable but it's more convenient to have a tool that
automates the process and finds the required dependencies.


Sounds like a good idea to me, if a sensible name is chosen for the
"main module" (I propose 'main':-). Take it to Python-Dev...? I even
wonder if it's unobtrusive enough to be considered (as a "bugfix"... :-)
for 2.3.1, rather than having to get into 2.4 and thus wait a LONG time...
Alex
Jul 18 '05 #5
Oren Tirosh <or*******@hish ome.net> writes:
On Wed, Aug 06, 2003 at 08:36:20PM +0200, Thomas Heller wrote:
I'm currently working on a new version of py2exe, which will require
Python 2.3 and later, because it uses the zipimport mechanism.
Now that zipimport is part of Python the code required for bootstrapping
a py2exe runtime is just:

myscript -c "import sys; sys.path.insert (0, sys.executable) ; import foo"


Yes, something like this is also what I am thinking now. And 'myscript'
is just a copy of the standard interpreter. Although the sys.path entry
must be present *before* Py_Initialize is called.
This reduces the difference between the custom interpreter supplied with
py2exe and the standard interpreter to just a few lines of C.

The obvious question is - why not go all the way and put this little
hook into the standard Python distribution? This way py2exe could be a
platform-independent pure Python application. In fact, py2exe wouldn't
actually be necessary because anyone could create a zip file manually and
append it to the executable but it's more convenient to have a tool that
automates the process and finds the required dependencies.


Yes, and modulefinder is now in the standard library.

OTOH, py2exe does a little bit more: It has a mechanism to supply
modules to include which modulefinder doesn't find, exclude modules
which are unneeded although found, can detect whether Tkinter is used
and copy it, scan (on Windows) extensions for dlls they need (wxPython
needs the wxWindows dll, for example), handle hidden imports from C code
in Python itself and extensions, and so on.

And it works around the fact that extension modules cannot be loaded
from zipfiles, it creates a pure Python loader included in the zip for
them.

Having said that, I would have nothing against py2exe included in the
standard distribution, and the hooks in place.

Thanks,

Thomas
Jul 18 '05 #6
Alex Martelli <al***@aleax.it > writes:
Oren Tirosh wrote:
On Wed, Aug 06, 2003 at 08:36:20PM +0200, Thomas Heller wrote:
I'm currently working on a new version of py2exe, which will require
Python 2.3 and later, because it uses the zipimport mechanism.
Now that zipimport is part of Python the code required for bootstrapping
a py2exe runtime is just:

myscript -c "import sys; sys.path.insert (0, sys.executable) ; import foo"

This reduces the difference between the custom interpreter supplied with
py2exe and the standard interpreter to just a few lines of C.

The obvious question is - why not go all the way and put this little
hook into the standard Python distribution? This way py2exe could be a
platform-independent pure Python application. In fact, py2exe wouldn't
actually be necessary because anyone could create a zip file manually and
append it to the executable but it's more convenient to have a tool that
automates the process and finds the required dependencies.


Sounds like a good idea to me, if a sensible name is chosen for the
"main module" (I propose 'main':-).


My choice would have been __main__ :-) Is it really the correct way to
'import __main__' instead of 'running' it?
Take it to Python-Dev...? I even wonder if it's unobtrusive enough to
be considered (as a "bugfix"... :-) for 2.3.1, rather than having to
get into 2.4 and thus wait a LONG time...
Alex


Thomas
Jul 18 '05 #7
Thomas Heller wrote:
...
myscript -c "import sys; sys.path.insert (0, sys.executable) ; import foo"
... Sounds like a good idea to me, if a sensible name is chosen for the
"main module" (I propose 'main':-).


My choice would have been __main__ :-) Is it really the correct way to
'import __main__' instead of 'running' it?


Well, most main scripts ARE coded with the "if __name__=='__ma in__':"
convention, after all, so an "import __main__" can be seen as a way
to just piggyback on that existing convention rather than inventing a
new one in addition. So, I concede it's better than "import main".
Alex

Jul 18 '05 #8
Alex Martelli <al***@aleax.it > writes:
Thomas Heller wrote:
...
myscript -c "import sys; sys.path.insert (0, sys.executable) ; import foo" ... Sounds like a good idea to me, if a sensible name is chosen for the
"main module" (I propose 'main':-).


My choice would have been __main__ :-) Is it really the correct way to
'import __main__' instead of 'running' it?


Well, most main scripts ARE coded with the "if __name__=='__ma in__':"
convention, after all, so an "import __main__" can be seen as a way
to just piggyback on that existing convention rather than inventing a
new one in addition. So, I concede it's better than "import main".


How would the hook be triggered? The zipimporter code would probably add
argv[0] to sys.path, and then try to 'import __main__' or something like
this. The problem is that a standalone executable python would have to
disable the standard Python command line flags and environment
variables, but they are parse *before* Py_Initialize() is called.

And I hope that the options set by the command line flags and env vars
should now come from the __main__ script itself.

Thomas
Jul 18 '05 #9
Thomas Heller wrote:
Alex Martelli <al***@aleax.it > writes:
Thomas Heller wrote:
...
> myscript -c "import sys; sys.path.insert (0, sys.executable) ; import
> foo" ...
Sounds like a good idea to me, if a sensible name is chosen for the
"main module" (I propose 'main':-).

My choice would have been __main__ :-) Is it really the correct way to
'import __main__' instead of 'running' it?


Well, most main scripts ARE coded with the "if __name__=='__ma in__':"
convention, after all, so an "import __main__" can be seen as a way
to just piggyback on that existing convention rather than inventing a
new one in addition. So, I concede it's better than "import main".


How would the hook be triggered? The zipimporter code would probably add
argv[0] to sys.path, and then try to 'import __main__' or something like
this. The problem is that a standalone executable python would have to
disable the standard Python command line flags and environment
variables, but they are parse *before* Py_Initialize() is called.


Ah, yes, good point. So, the executable needs to know whether to do
the usual commandline and environment processing, or not, _before_
calling Py_Inizialize. One approach might be to trigger this based
on the executable's own *name* -- do the full commandline and environment
processing if and only if the executable's name starts with (case-
insensitive, probably, to be safe...) the six letters 'python', but
not otherwise. There are, no doubt, other alternative ways, too, but
this one seems dirt-simple and practically sufficient.

And I hope that the options set by the command line flags and env vars
should now come from the __main__ script itself.


I'm not sure I understand what you mean. Anyway, I do see that if
my 'foobar.exe' is a python.exe + appended zipfile, then running
'foobar -i' should just put '-i' in sys.argv[1], and NOT gobble it up
to mean "enter interactive mode", for example.
Alex

Jul 18 '05 #10

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

Similar topics

0
2983
by: RJS | last post by:
Hi all, I can't get a py2exe compiled app to run with numarray (numarray-0.5.win32- py2.2). Also wxPythonWIN32-2.3.3.1-Py22 and ActivePython-2.2.1-222. In the sample below, commenting out "import numarray" allows the exe to run. Left in, I get "4.exe has generated errors" etc. I'm going around and around and there isn't much on Google. py2exe output is last.
2
3668
by: Thomas Heller | last post by:
"Brad Clements" <bkc@murkworks.com> writes: > Once again I apologize for posting this py2exe question in the ctypes list. ;-) In the long run, this will be the wrong forum. I suggest comp.lang.python (or should a py2exe mailing list be created?). And I'm cc'ing to python-list. > > I need to ship a Windows service in py2exe, but I also want a
6
2123
by: Brad Clements | last post by:
Now that Thomas is back from vacation ;-) I cannot get the example service to work using Python 2.3 and the latest released py2exe (or the cvs version) on Win2k SP3. I can run the sample service .py file ok, but once it's inside a py2exe generated exe.. no working. The error in the event log is: The description for Event ID ( 240 ) in Source ( MyService ) cannot be found. The local computer may not have the necessary registry...
3
3634
by: ulysses | last post by:
hi. I use python 23,py2exe 0.4.3 ,wxpython do my py app in win32. I use gettext to support multi languages. I build a small fuction for load language at top of main module. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def setLan(lan): import gettext langs = gettext.GNUTranslations(open (join ( localPath, ( "lan/"+lan+".mo" ) )
11
3379
by: Timothy Smith | last post by:
is it possible instead of py2exe putting all library's in a zip file, to just put them in a sub dir?
1
1515
by: Alois Weber | last post by:
I'm not shure wether its the right place to ask here. But I don't know where to ask else. Does anybody know a free crossplatform library (for linux/windows perhaps Mac) which offers some classes like the ADODB.Recordset or DataSource from Delphi? I'm thinking of a rowset where you have a current selected record which is deletable and where you can add new records. It should also have some notification to bind it against
2
1634
by: Jimmy Retzlaff | last post by:
I am taking over the maintenance and support of py2exe from Thomas Heller. As he announced a few weeks ago he is looking to focus on other things. py2exe has been very useful to me over the years and I look forward to keeping it every bit as useful in the future. I plan to make the transition as smooth as possible for users of py2exe. I don't plan to make changes to the license other than adding my name to the list of people not to sue....
12
1675
by: chardish | last post by:
Hello, I'm trying to build an executable with py2exe, but unfortunately the version I have is 0.6.6, which has a rather annoying bug that doesn't let you rename the executable file if you bundle everything in a single executable. It seems fairly unacceptable to tell our customers that they can't rename a file we send them. I hear this problem is fixed in 0.6.8, but unfortunately there's no standalone installer for py2exe 0.6.8 - the...
4
2012
by: Gabriel Rossetti | last post by:
Hello everyone, I like to create a cross-platform standalone python application, like Mac OS *.app dirs. The idea is to distribute a zip file containing everything (the python interpreter and all) so that a user just unzips it and runs it. Has anyone ever done anything like that? I searched google but didn't find anything really, and currently, even in my dev env, I have to set the PYTHONPATH manually, and for a standalone app I...
0
8242
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8177
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,...
0
8681
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8341
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
8488
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...
1
6112
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
4084
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
4183
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.