473,416 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

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

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 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.win3 2\\winexe\\lib\\Programme\\ActivePython22\\Lib\\si te-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
Jul 18 '05 #1
2 17612
[posted and mailed]
st********@inpro.de (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
-----
from distutils.core import setup
setup(name="WMI_tester", scripts=["WMI_tester.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
Jul 18 '05 #2
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
Jul 18 '05 #3

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

Similar topics

2
by: Chris Hodapp | last post by:
I have seen messages posted about this before, and there is a clear reference to it in the manual, but I have been unable to find a solution. I'm on Slackware 9.1, kernel 2.6.0-test11, using...
2
by: Sebastian Stelzer | last post by:
Hi, I'am a beginner in Python and I have got a problem with the TKInter module. When I want to start e.g. pysol, I get following output: Traceback (most recent call last): File...
12
by: Georg Brandl | last post by:
Hello, in follow-up to the recent "dictionary accumulator" thread, I wrote a little module with several subclassed dicts. Comments (e.g. makes it sense to use super), corrections, etc.? Is...
0
by: Bill Davy | last post by:
Hello, I am using SWIG-1.3.24 to make an extension (called SHIP) to Python2.4.1 and then running under IDLE (if that makes any difference) but when I "import SHIP" I get: >>> import SHIP ...
0
by: Bill Davy | last post by:
I am working with MSVC6 on Windows XP. I have created an MSVC project called SHIP I have a file SHIP.i with "%module SHIP" as the first line (file is below). I run SHIP.i through SWIG 1.3.24...
3
by: Mac Campbell | last post by:
For some unknown reason my mdb seemed to drop a module I had named "Utilities". I tried to copy the module back in from a backup copy and got the error message "<<MyProject>> is currently unable to...
0
by: Robert Dailey | last post by:
I created a basic python file and made an attempt to execute it from the command line, however it gives me a weird error after the python file has been executed: Traceback (most recent call...
1
by: Prof Rodney Coates | last post by:
Although I have been using Macs for a quarter of a century and was doing scientific programming in the '60's I am VERY new to Python on the Mac. I have been writing some very simple applications and...
4
by: Daniel | last post by:
Hello, I'm trying to build a very simple IPC system. What I have done is create Data Transfer Objects (DTO) for each item I'd like to send across the wire. I am serializing these using...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.