[python-win32] Re: Problems with py2exe and COM
Thomas Heller
theller at python.net
Tue Dec 30 09:48:27 EST 2003
"Giles A. Radford" <moof at metamoof.net> writes:
> On Mon, Dec 29, 2003 at 10:30:19PM +0100, Thomas Heller wrote:
>> Are you using py2exe 0.4.x? If so, you should switch to the (soon to be
>> officially released) version 0.5. Prereleases are in the Sourceforge
>> project page, in the downloads section. Note that these currently
>> require win NT, 2k, or XP, and Python 2.3, and, for COM, win32all 163.
>
> It works a dream, apart form the fact that you can't seem to use python
> 2.3 to be a client for a python 2.3 server inside a DLL. But I read
> somewhere that's a known problem. Any idea if it's solvable at all?
Maybe. Currently the only workaround (if you want to use the 'frozen'
com server from a Python script) is to either use the EXE server, not
the DLL server, or to use a different Python version.
> The configuration file was a bit abstruse to understand, but I managed
> to get the gist fo it in the end. In the advanced sample, you may, for
> clarity, want to make the com_server line point to the interp object you
> set up earlier
>
>> There's no documentation so far ;-)
>
> This seems to be a weakness of PythonCOM generally. If you give me a
> heads up and are willign to answer questions, I'm quite happy to at
> least start documenting py2exe for you...
Oh, that would be very cool. To get you started, I append what I
currently have - this is a text file, later converted to html, by a
StructuredText module I ripped off an old version of zope. Using Rest
would definitely be an advantage, OTOH contents is more important than
markup.
Other possibilities would be to use the py2exe and ctypes wiki at
<http://starship.python.net/crew/theller/moin.cgi/FrontPage>
> OK: next question- Do I really need everythin in "build", or can I just
> send webupdater.dll and the library.zip file over? How exactly does this
> work? If so, what's the best place for this stuff to be installed on a
> standard windows installation? I have a bunch of dlls, including
> python23.dll, a bunch of .pyds and a library.zip file
I assume you mean the "dist" directory - the "build" directory is only
needed for the build process. Yes, you have to distribute all what you
find there. Python modules are in the library.zip file, the .exe and/or
.dll is the executable itself, python23.dll is needed, and since
extension modules (.pyd) cannot be loaded from zipfiles, they are also
in this directory.
Installing them on another machine, the dist directory should probably
be installed somewhere below "\Program Files".
> Incidentally, My co-programmer is getting rather annoyed that the python
> objects I've created aren't showing up under VB at all. He's tryign to
> get things like autocompletion of method names going. Any idea how I
> could get that going? Or at least get the application showing up on his
> list of things to include?
I guess you need a typelibrary, but I may be wrong - I never use VB.
Thomas
-------------- next part --------------
Convert python scripts into standalone windows programs
Copyright (c) 2001, 2002, 2003 Thomas Heller, Mark Hammond
Abstract
'py2exe' is a Python
"distutils":http://www.python.org/doc/current/dist/ extension
which converts python scripts into executable windows programs,
able to run without requiring a python installation.
It has been used to create wxPython, Tkinter, Pmw, PyGTK, pygame,
win32com client and server modules and other standalone programs.
'py2exe' is distributed under an open-source
"license":LICENSE.TXT.
News
XXX
Using py2exe
Assuming you have writtern a python script 'myscript.py' which you
want to convert into an executable windows program, able to run on
systems without a python installation. If you don't already have
written a *distutils*
"setup-script":http://www.python.org/doc/current/dist/setup-script.html,
write one, and insert the statement 'import py2exe' before the
call to the setup function::
# setup.py
from distutils.core import setup
import py2exe
setup(console=["myscript.py"])
Running::
python setup.py py2exe --help
will display all available command-line flags to the 'py2exe'
command.
Now you can call the setup script like in this way::
python setup.py py2exe
and a subdirectory 'dist' will be created, containing the files
'myscript.exe', 'python23.dll', and 'library.zip'. If your script
uses compiled C extension modules, they will be copied here as
well, also all dlls needed at runtime.
These files include everything that is needed for your program,
and you should distribute the whole directory contents.
The above setup script creates a console program, if you want a
GUI program without the console window, simply replace
'console=["myscript.py"]' by 'windows=["myscript.py"]'.
'py2exe' can create more than one exe file in one run, this is
useful if you have a couple of related scripts. Pass a list of
all scripts in the 'console' and/or 'windows' keyword argument.
Specifying additional files
Some applications need additional files at runtime, like
configuration files, fonts, or bitmaps.
'py2exe' can copy these files into subdirectories of 'dist' if
they are specified in the setup script with the 'data_files'
option. 'data_files' should contain a sequence of '(target-dir,
files)' tuples, where files is a sequence of files to be copied.
Here's an example::
# setup.py
from distutils.core import setup
import glob
import py2exe
setup(console=["myscript.py"],
data_files=[("bitmaps",
["bm/large.gif", "bm/small.gif"]),
("fonts",
glob.glob("fonts\\*.fnt"))],
)
This would create a subdirectory 'dist\bitmaps', containing the
two '.gif' files, and a subdirectory 'dist\fonts', containing all
the '.fnt' files.
How does it work?
'py2exe' uses python's *'modulefinder'* to examine your script and
find all python and extension modules needed to run it. Pure
python modules are compiled into '.pyc' or '.pyo' files in a
temporary directory. Compiled extension modules ('.pyd') are also
found and parsed for binary dependencies.
A zip-compatible archive is built, containing all python files
from this directory. Your main script is inserted as a resource
into a custom embedded python interpreter supplied with py2exe,
and the zip-archive is installed as the only item on 'sys.path'.
In simple cases, only 'pythonxx.dll' is needed in addition to
'myscript.exe'. If, however, your script needs extension modules,
unfortunately those cannot be included or imported from the
zip-archive, so they are needed as separate files (and are copied
into the 'dist' directory).
*Attention*: 'py2exe' tries to track down all binary dependencies
for all pyd's and dll's copied to the dist directory recursively,
and copies all these dependend files into the dist
directory. 'py2exe' has a builtin list of some system dlls which
are not copied, but this list can never be complete.
Installing py2exe
Download and run the installer
"py2exe-0.5.0a7.win32-py2.3.exe":http://prdownloads.sourceforge.net/py2exe/py2exe-0.5.0a7.win32-py2.3.exe?download.
This installs py2exe together with some samples, the samples are
in the 'lib\site-packages\py2exe\samples' subdirectory.
For Windows 95/98/Me, you additionally need the *Microsoft Layer
for Unicode on Windows 95/98/ME Systems (MSLU)* dll from
"here":http://www.microsoft.com/msdownload/platformsdk/sdkupdate/psdkredist.htm.
Run the self-extracting 'unicows.exe' file, and copy the unpacked
'unicows.dll' file in the directory which contains your
'python.exe'. Note that this is only needed on the machine where
you want to build executables with 'py2exe', it is not required on
the machine where you want to run the created programs.
More information about the Python-win32
mailing list