Mailing List Archive

Problem using freeze with pywintypes
I have discovered minor problem with using freeze with win32all
modules by Mark Hammond. This occurs mainly because the name
"PyWinTypes15.dll" given for the "pywintypes" module dll. (I am posting
this because I don't want someone else to waste time on understanding
the same problem).

The problem and workaround are described as follows.

1. Create a small script test.py

------------------------------------------------------------
test.py
------------------------------------------------------------
import pywintypes
import win32file

ovstruct = pywintypes.OVERLAPPED()
print 'hello World\n'.

Unless "PYTHONEX" enviroment variable is set to the top level
directory where sources for "win32all" modules reside, none of the
win32* (and also pywintypes) module will get built into test.exe.

Case A: PYTHONEX not set
-------------------------

2. freeze.py -p %pythonsrc% -o Build will try to build test.exe to
be built in subdirectory "Build".

3. Copy test.exe, PyWinTypes15.dll, python15.dll and win32file.pyd
to a machine on which python is not installed. move
PyWinTypes15.dll and python15.dll %systemroot%\system32
directory.

4. set PYTHONPATH=%cd%

5. type test.exe.

Following error appears:
"ImportError: No module named pywintypes".

This occurs because "import pywintypes" statement causes core
python's
"find_module" function to be called, which looks for

1. pywintypes.dll
2. pywintypes.pyd
3. pywintypes.pyc
4. pywintypes.py

in %PYTHONPATH% and cannot find it there. Python on win32 also
examines registry key:

HKLM\SOFTWARE\Python\PythonCore\1.5\Modules\<module-name>

In case such a key exists, it's value is taken as the
"full-pathname" of the dll from which module can be loaded. When
win32all-xxx.exe is installed, it creates such key for pywintypes
and some other modules. For pywintypes, the value is of REG_SZ
type and points to "C:\WINNT\system32\PyWinTypes15.dll". On the
machine where it is not installed, "import fails".

Renaming PyWinTypes15.dll PyWinTypes.dll will work if the script
used *only* pywintypes module. If it uses any other module like
win32file, it rename creates problem because win32file.pyd
"depends" on PyWinTypes15.dll.

WORKAROUND:
----------

1. Create a text file follwing contents and name it as "pyreg.ini"

\registry\machine\software\python
PythonCore
1.5
Modules
=
pythoncom
= REG_EXPAND_SZ %systemroot%\System32\pythoncom15.dll
pywintypes
= REG_EXPAND_SZ %systemroot%\System32\PyWinTypes15.dll


2. copy pyreg.ini to the target machine on which exe is used, and
type "regini pyreg.ini". (This can be automated through simple
windows cmd script very easliy. The script can launch test.exe
automatically after creating registry keys).


Case B: PYTHONEX is set to correct value
----------------------------------------
freeze.py -p %pythonsrc% -o Build will try to build test.exe to
be built in subdirectory "Build".

This fails with a linker error,
"pywintypes.lib" not found.

because the Makefile created by freeze.py does not give full path
for pywintypes.lib. This can be patched by changing
win32makemakefile.py to treat pywintypes module specially. (All
the win32****.pyd modules, depend on pywintypes.lib).

Hope this helps.

Thanks
asang..


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.