py2exe: "ImportError: No module named pywintypes" ...?? :-(

X

x-herbert

Hi,

I have a small test to "compile" al litle script as a WMI-Tester. The
script include a wmi-wrapper and "insert" the Win32-modeles.

here the code:

my "WMI-Tester.py"
-----
import wmi
computer = wmi.WMI ()
for item in computer.Win32_Process ():
print item
-----

the WMI-Wrapper
----
....
import win32com.client
import pywintypes
....
=> look at http://tgolden.sc.sabren.com/python/wmi.html
-----

the py2exe-setup.py
-----
from distutils.core import setup
setup(name="WMI_tester", scripts=["WMI_tester.py"],)
-----

and the error at
"setup.py py2exe":running build
running build_scripts
not copying WMI_tester.py (up-to-date)
running install_scripts
not copying build\scripts-2.2\mailtest.py (output up-to-date)
not copying build\scripts-2.2\script11.py (output up-to-date)
not copying build\scripts-2.2\watchdog.py (output up-to-date)
not copying build\scripts-2.2\wmi.py (output up-to-date)
not copying build\scripts-2.2\WMI_tester.py (output up-to-date)
+----------------------------------------------------
| Processing script WMI_tester.py with py2exe-0.4.1
+----------------------------------------------------
Searching modules needed to run 'WMI_tester.py' on path:
['C:\\Dokumente und Einstellungen\\steinha\\Eigene
Dateien\\WinProcess\\PythonProc\\build\\bdist.win32\\winexe\\lib\\Programme\\ActivePython22\\Lib\\site-packages',
'', 'C:\\Programme\\ActivePython22\\Lib\\site-packages\\Pythonwin',
'C:\\Programme\\ActivePython22\\Lib\\site-packages\\win32',
'C:\\Programme\\ActivePython22\\Lib\\site-packages\\win32\\lib',
'C:\\Programme\\ActivePython22\\Lib\\site-packages',
'C:\\Programme\\ActivePython22\\DLLs',
'C:\\Programme\\ActivePython22\\lib',
'C:\\Programme\\ActivePython22\\lib\\lib-tk',
'C:\\Programme\\ActivePython22',
'C:\\Programme\\ActivePython22\\lib\\site-packages\\Numeric',
'C:\\Programme\\ActivePython22\\lib\\site-packages\\PIL',
'C:\\Dokumente und Einstellungen\\steinha\\Eigene
Dateien\\WinProcess\\PythonProc']
Traceback (most recent call last):
File "C:\Programme\ActivePython22\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py",
line 301, in RunScript
exec codeObject in __main__.__dict__
File "C:\Dokumente und Einstellungen\steinha\Eigene
Dateien\WinProcess\PythonProc\setup-py2exe.py", line 7, in ?
setup(name="WMI_tester", scripts=["WMI_tester.py"],)
File "C:\Programme\ActivePython22\lib\distutils\core.py", line 138,
in setup
dist.run_commands()
File "C:\Programme\ActivePython22\lib\distutils\dist.py", line 893,
in run_commands
self.run_command(cmd)
File "C:\Programme\ActivePython22\lib\distutils\dist.py", line 913,
in run_command
cmd_obj.run()
File "C:\Programme\ActivePython22\Lib\site-packages\py2exe\build_exe.py",
line 604, in run
mf.import_hook(f)
File "C:\Programme\ActivePython22\Lib\site-packages\py2exe\tools\modulefinder.py",
line 126, in import_hook
q, tail = self.find_head_package(parent, name)
File "C:\Programme\ActivePython22\Lib\site-packages\py2exe\tools\modulefinder.py",
line 180, in find_head_package
raise ImportError, "No module named " + qname
ImportError: No module named pywintypes

In the python-enviroment works the script fine - why the
import-error???

CU Ingolf
 
T

Thomas Heller

[posted and mailed]
(e-mail address removed) (x-herbert) writes:

(Herbert, athough you have also sent mail privately to me I prefer to
answer on the newsgroup, just for the archives)
Hi,

I have a small test to "compile" al litle script as a WMI-Tester. The
script include a wmi-wrapper and "insert" the Win32-modeles.

here the code:

my "WMI-Tester.py"
-----
import wmi
computer = wmi.WMI ()
for item in computer.Win32_Process ():
print item
-----
Ok. After installing wmi.py and rebooting my machine, this works for me
when run from Python.
the py2exe-setup.py
This script is not complete (but certainly a cut and paste error), you
have to add 'import py2exe'.
and the error at
"setup.py py2exe": ....
Traceback (most recent call last):
File "C:\Programme\ActivePython22\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py",
line 301, in RunScript
exec codeObject in __main__.__dict__
File "C:\Dokumente und Einstellungen\steinha\Eigene
Dateien\WinProcess\PythonProc\setup-py2exe.py", line 7, in ?
setup(name="WMI_tester", scripts=["WMI_tester.py"],)
File "C:\Programme\ActivePython22\lib\distutils\core.py", line 138,
in setup
dist.run_commands()
File "C:\Programme\ActivePython22\lib\distutils\dist.py", line 893,
in run_commands
self.run_command(cmd)
File "C:\Programme\ActivePython22\lib\distutils\dist.py", line 913,
in run_command
cmd_obj.run()
File "C:\Programme\ActivePython22\Lib\site-packages\py2exe\build_exe.py",
line 604, in run
mf.import_hook(f)
File "C:\Programme\ActivePython22\Lib\site-packages\py2exe\tools\modulefinder.py",
line 126, in import_hook
q, tail = self.find_head_package(parent, name)
File "C:\Programme\ActivePython22\Lib\site-packages\py2exe\tools\modulefinder.py",
line 180, in find_head_package
raise ImportError, "No module named " + qname
ImportError: No module named pywintypes

It seems that either your installation is corrupted or py2exe doesn't work with
ActiveState Python any longer, py2exe 0.4.1 requires a fairly new build
of the win32 extensions (154 or later, IIRC). Mark changed the way the special
pywintypes and pythoncom extensions are imported.
For me (Python 2.2.2, and a recent win32all) the py2exe build process
runs successfully.

The deeper problem occurs when the executable is run:

c:\wmi\dist\wmi-tester>wmi-tester.exe
Traceback (most recent call last):
File "<string>", line 1, in ?
File "imputil.pyc", line 103, in _import_hook
File "<string>", line 52, in _import_top_module
File "imputil.pyc", line 216, in import_top
File "imputil.pyc", line 271, in _import_one
File "<string>", line 128, in _process_result
File "wmi.pyc", line 117, in ?
File "win32com\client\gencache.pyc", line 435, in EnsureDispatch
File "win32com\client\gencache.pyc", line 419, in EnsureModule
File "win32com\client\gencache.pyc", line 236, in MakeModuleForTypelib
File "win32com\client\makepy.pyc", line 273, in GenerateFromTypeLibSpec
File "win32com\client\gencache.pyc", line 449, in AddModuleToCache
File "win32com\client\gencache.pyc", line 473, in _GetModule
File "imputil.pyc", line 132, in _import_hook
File "<string>", line 70, in _finish_import
File "imputil.pyc", line 318, in _load_tail
ImportError: No module named win32com.gen_py

That is because the wmi module uses early binding to get some COM
constants described in a type library. For this, one would need to use
the --progids option to py2exe, so that the win32com.gen_py directory
which contains the makepy output is included into the exe.

Unfortunately this only works for *modules* in this directory, and not
(yet?) for packages, but wmi requires/creates a package named
565783C6-CB41-11D1-8B02-00600806D9B6x0x1x2 here, and I cannot come up
with a quick hack right now, neither do I know how to guess this name.

And I don't even find docs for win32com.client.GetObject("winmgmts:").
How can I, from this call, find out the typelib guid and version?

Also, I'm not sure if it is a good idea to include the makepy generated
modules into the executable. Maybe it would be better to create them at
runtime in a subdirectory (and include the makepy module into the exe).

Can anyone help?

Thomas
 
X

x-herbert

Hi Thomas,

thank you for the fast replay (I dont forget the "import py2exe")

I´ll try your tips...

May be have anybody a good solution...

CU Ingolf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top