472,785 Members | 1,214 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,785 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 17476
[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...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.