I tried both
pip install pypiwin32
and
pip install pywin32
and they both succeeded on my Windows 7 x64 / Python 2.7.15 64-bit (it's the only Python I have installed on my PC). I even did:
python C:\Python27\Scripts\pywin32_postinstall.py -install
and it successfully returned:
...
Shortcut to documentation created
The pywin32 extensions were successfully installed.
Still I get, when doing import pywin32
:
ImportError: No module named pywin32
How to install pywin32
on Windows 7?
The solution is indeed
import win32api
instead of import pywin32
!
I'm just putting this here in case someone is interested. This is an exerpt from the book Python Programming On Win32: Help for Windows Programmers written by M. Hammond and A. Robinson listing modules in the Pywin32
package (or the win32all
package as it was called before):
mmapfile
- Interfaces to Windows memory-mapped files, a mechanism that allows data to be shared among multiple processes.
odbc
- An interface to the Open DataBase Connectivity API, a portable API for connection to multiple database.
win32api
- Accesses many of the common and simple Windows APIs; a general-purpose module with a cross section of API support.
win32event
- Accesses the Windows even the signaling API. This module allows you to manipulate and wait for Windows events, semaphores, mutexes, etc.
win32evtlog
,win32evtlogutil
- An interface to the Windows NT Event Log. Thewin32evtlog
module provides a raw interface to the Windows NT API, while thewin32evtlogutil
module provides utilities to simplify working with the module.
win32pdh
- An interface to the Windows NT Performance Monitor. This module uses a helper DLL provided by Microsoft known as the Performance Data Helper or PDH.
win32pipe
- Accesses the pipe-related Win32 functions, such as functions for creating and using pipes, named pipes.
win32file
- Accesses the file-related Win32 functions. This module exposes a low-level, raw interface to files on Windows and is used only when the standard Python file object isn't suitable.
win32lz
- An interface to the Windows LZ compression library. Note that since this module was created, Python now ships with support for the gzip compression format, so in most cases win32lz is no longer used.
win32net
,win32wnet
- Interface to the Windows networking API.win32net
provides an interface to Windows NT-specific server networking, whilewin32wnet
provides client-networking functions available to all versions.
win32print
- Interface to the printer-related Windows APIs.
win32process
- Interface to the process-related Windows APIs.
win32ras
- Interface to the Windows Remote Access Service (RAS). Used for establishing remote connections to Windows NT servers, typically using a modem.
win32security
- Accesses the Windows NT security-related functions.
win32service
,win32serviceutil
- Access the Windows NT Services-related API.
win32trace
,win32traceutil
- Debugging related modules. These modules allow you to collect the output of a Python process in a separate process. This is most useful when debugging server-style application, where Python error and other messages are not available.
Note: The content may be a bit out of date as the book was published in 2000.
as of now 09.06.2023 you'll get this error in IDLE 3.11.3:
import win32api
Traceback (most recent call last):
File "<pyshell#473>", line 1, in <module>
import win32api
ModuleNotFoundError: No module named 'win32api'
to circumvent that all you have to do is use the from statement:
from win32 import win32api
which will work like a charm
if you still encounter any errors the py32win provided a file called pywin32_postinstall.py , its located in the *\Python311\Scripts\ Folder and if you excecute it with the -install argument it will try to fix the installation which will look like so
C:\Users\%Username%\Appdata\Local\Programs\Python\Python311\Scripts\pywin32_postinstall.py -install
note however that COM objects cannot be installed without administrative privileges (i had no problems whatsoever, it wasn't needed for me)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.