ImportError:没有名为 win32api、python 的模块,即使 win32api 的位置附加到路径中也是如此

发布于 2024-10-18 08:14:42 字数 1209 浏览 5 评论 0原文

我对 python 还很陌生。 (Python 2.6)

我试图通过导入 wmi 模块来列出正在运行的进程。

import wmi
sys.path.append(r'C:\Python26\Lib\site-packages\isapi\test\build\bdis.win32\winexe\temp')
c = wmi.WMI () 
for process in c.Win32_Process ():
    print process.ProcessId, process.Name

系统搜索表明在上述代码的append 语句中的位置找到了win32api。但我仍然收到错误: ImportError:没有名为 win32api 的模块

实际错误:

Traceback (most recent call last):
  File "C:\Documents and Settings\xxxx\Desktop\Python\Practice Code\file.py", line 1, in <module>
    import wmi
  File "C:\Python26\lib\site-packages\wmi.py", line 88, in <module>
    from win32com.client import GetObject, Dispatch
  File "C:\Python26\lib\site-packages\win32com\__init__.py", line 5, in <module>
    import win32api, sys, os
ImportError: No module named win32api

我已经安装了 win32extensions 确保版本和平台匹配。我用的是2.6 我还安装了 wmi-1.4.6

我的路径:

C:\Documents and Settings\xxxx\Desktop\Python\Practice Code
C:\Python26\Lib\idlelib
C:\WINDOWS\system32\python26.zip
C:\Python26\DLLs
C:\Python26\lib
C:\Python26\lib\plat-win
C:\Python26\lib\lib-tk
C:\Python26
C:\Python26\lib\site-packages

有什么想法吗?

I'm fairly new to python. (Python 2.6)

I'm trying to list the running processes by importing the wmi module.

import wmi
sys.path.append(r'C:\Python26\Lib\site-packages\isapi\test\build\bdis.win32\winexe\temp')
c = wmi.WMI () 
for process in c.Win32_Process ():
    print process.ProcessId, process.Name

A system search pointed to win32api being found at the location in the append statement in the code above. But I still get the error: ImportError: No module named win32api

The actual error:

Traceback (most recent call last):
  File "C:\Documents and Settings\xxxx\Desktop\Python\Practice Code\file.py", line 1, in <module>
    import wmi
  File "C:\Python26\lib\site-packages\wmi.py", line 88, in <module>
    from win32com.client import GetObject, Dispatch
  File "C:\Python26\lib\site-packages\win32com\__init__.py", line 5, in <module>
    import win32api, sys, os
ImportError: No module named win32api

I've installed win32extensions making sure the versions and platform match. I'm using 2.6
I've also installed wmi-1.4.6

My path:

C:\Documents and Settings\xxxx\Desktop\Python\Practice Code
C:\Python26\Lib\idlelib
C:\WINDOWS\system32\python26.zip
C:\Python26\DLLs
C:\Python26\lib
C:\Python26\lib\plat-win
C:\Python26\lib\lib-tk
C:\Python26
C:\Python26\lib\site-packages

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绾颜 2024-10-25 08:14:42

这应该包含您需要的所有信息:

http://mail. python.org/pipermail/python-win32/2003-December/001482.html

不需要WMI,只需使用Win32扩展。

from win32com.client import GetObject
WMI = GetObject('winmgmts:')

#List all processes
processes = WMI.InstancesOf('Win32_Process')
for process in processes:
    print process.Properties_('Name')

#Get a specific process
p = WMI.ExecQuery('select * from Win32_Process where Name="chrome.exe"')
#view all possible properties
for prop in p[0].Properties_:
    print prop
#print out PID
print p[0].Properties_('ProcessId').Value

彼得

This should have all the information you need:

http://mail.python.org/pipermail/python-win32/2003-December/001482.html

No need to for WMI, just use Win32 Extensions.

from win32com.client import GetObject
WMI = GetObject('winmgmts:')

#List all processes
processes = WMI.InstancesOf('Win32_Process')
for process in processes:
    print process.Properties_('Name')

#Get a specific process
p = WMI.ExecQuery('select * from Win32_Process where Name="chrome.exe"')
#view all possible properties
for prop in p[0].Properties_:
    print prop
#print out PID
print p[0].Properties_('ProcessId').Value

Peter

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文