ImportError: no module named win32api, python, even if win32api location is added to the path

I am new to python. (Python 2.6)

I am trying to list running processes by importing a 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 pointing to win32api is located in the append statement in the above code. But I still get the error message: ImportError: There is no module named win32api

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 installed win32extensions, making sure the versions and platform match. I am using 2.6 I also installed wmi-1.4.6

My way:

 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?

+4
source share
1 answer

Here should be all the necessary information:

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

Not needed 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

+2
source

Source: https://habr.com/ru/post/1340792/


All Articles