[Distutils] pywin32 egg?

Phillip J. Eby pje at telecommunity.com
Sat Jul 7 14:29:35 CEST 2007


At 03:20 PM 7/7/2007 +1000, Mark Hammond wrote:
>Hi Jim,
>
> > Since you happen to be paying attention to distributions atm ... :)
> >
> > I would love to see a pywin32 egg, which by definition, didn't need
> > to modify anything when it was installed. I guess there are some
> > features in pywin32 that wouldn't work with such a setup, but I'm
> > guessing that most features would.  Even if it wasn't called
> > pywin32,
> > I'd really like to see an egg that contained the parts of pywin32
> > that can be used without modifying anything on installation.
> >
> > Please. Pretty please. :)  It would make pywin32 much mroe
> > usable for
> > people using setuptools.
>
>I'm sure you know the drill - patches are always welcome :)  I've never
>modified a setup script to support eggs, and at this stage I'm more
>interested in getting existing functionality ported to x64 and Vista than
>creating a new distribution with reduced functionality.
>
>Also, if part of the functionality we had to drop was implementing COM
>objects (and we would if we couldn't install stuff into system32 or modify
>the HKLM part of the registry), then I'd be reluctant to call this a
>suitable distribution for anyone other than people wishing to package
>pywin32 with their own custom application, and I'd struggle to justify
>spending much time creating and supporting a distribution just for them.

I'm trying to remember for sure, but ISTR that I've successfully 
installed pywin32 in egg form.  Ah yes, I did, and it's working for 
me in one of my Python installations.  Don't remember how I did it though!

[pause to try and install it with easy_install in another Python installation]

Ah.  Okay, first, pywin32 isn't registered on PyPI, so you need a -f 
link to find the files:

    easy_install -f 
http://sourceforge.net/project/showfiles.php?group_id=78018 pywin32

This is easily fixed by adding a PyPI listing with the above URL 
registered as the "Download URL".

easy_install successfully installs the package, but in order to do 
the registry and copying stuff, the postinstall script has to be run:

$ Scripts/pywin32_postinstall.py -install
Traceback (most recent call last):
   File "Scripts\pywin32_postinstall.py", line 5, in ?
     pkg_resources.run_script('pywin32==210', 'pywin32_postinstall.py')
   File 
"c:\cygwin\home\pje\projects\setuptools-0.6\pkg_resources.py", line 
448, in run_script
     self.require(requires)[0].run_script(script_name, ns)
   File 
"c:\cygwin\home\pje\projects\setuptools-0.6\pkg_resources.py", line 
1166, in run_script
     execfile(script_filename, namespace, namespace)
   File 
"c:\cygwin\home\pje\chandlerstuff\chandler\release\bin\lib\site-packages\pywin32-210-py2.4-win32.egg\EGG-INFO\scripts\pywin32_postinstall.py", 
line 365, in ?
     install()
   File 
"c:\cygwin\home\pje\chandlerstuff\chandler\release\bin\lib\site-packages\pywin32-210-py2.4-win32.egg\EGG-INFO\scripts\pywin32_postinstall.py", 
line 155, in install
     LoadSystemModule(lib_dir, "pywintypes")
   File 
"c:\cygwin\home\pje\chandlerstuff\chandler\release\bin\lib\site-packages\pywin32-210-py2.4-win32.egg\EGG-INFO\scripts\pywin32_postinstall.py", 
line 94, in LoadSystemModule
     ('.dll', 'rb', imp.C_EXTENSION))
ImportError: DLL load failed: The specified module could not be found.

The problem here is that lib_dir is calculated using the system 
configuration, instead of by locating where the package is actually 
installed.  I changed the install() function like this:

      import timer
      lib_dir = os.path.dirname(timer.__file__)

Importing some other pywin32 module than 'timer' would be okay; it 
just looked like something small and unlikely to depend on anything 
else.  With this change, the install script produced this output::

$ Scripts/pywin32_postinstall.py` -install
Copied pythoncom24.dll to C:\WINDOWS\system32\pythoncom24.dll
Copied pywintypes24.dll to C:\WINDOWS\system32\pywintypes24.dll
Registered: Python.Interpreter
Registered: Python.Dictionary
Registered: Python
-> Software\Python\PythonCore\2.4\Help[None]=None
-> Software\Python\PythonCore\2.4\Help\Pythonwin 
Reference[None]='C:\\...\\lib\\site-packages\\pywin32-210-py2.4-win32.egg\\PyWin32.chm'
Creating directory 
C:\...\bin\lib\site-packages\pywin32-210-py2.4-win32.egg\win32com\gen_py
The pywin32 extensions were successfully installed.

Is there anything I can do to verify that this did in fact work correctly?

It appears that all would be needed for pywin32 to be fully 
easy_install-able would be this change to the postinstall script 
(which shouldn't affect its functionality for direct installation), 
and an entry on PyPI.  No setup script changed required -- or so it 
appears.  Anyone wishing to use the features enabled by the 
postinstall script would just need to run it with -install.

One question of course is, what features do you lose if you don't run 
the postinstall?  If I hadn't run it, would I still have been able to 
use Python to access COM objects exposed by other applications, or 
would I have been unable to do COM at all?



More information about the Distutils-SIG mailing list