Install & Compatibility
Where this runs
tested against v? · pip install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
build_error
glibcpy 3.10–3.910 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
win32api
✓ import win32api
win32con
✓ import win32con
win32gui
✓ import win32gui
win32com.client
✓ import win32com.client
pywintypes
✓ import pywintypes
✗ from win32 import pywintypes
While `pywintypes` might be found in a `win32` subdirectory in site-packages, the direct import is standard.
This quickstart demonstrates how to use the `win32com.client` module to automate Microsoft Excel, a common use case for pywin32. It shows how to dispatch an Excel application object, make it visible, create a new workbook, and write data to a cell. This requires Microsoft Excel to be installed on the Windows system where the code is run.
import win32com.client
import os
# This example demonstrates interacting with Microsoft Excel via COM.
# Ensure Excel is installed on the system.
try:
# Attempt to get an existing Excel application
excel = win32com.client.GetActiveObject("Excel.Application")
except:
# If no active Excel instance, create a new one
excel = win32com.client.Dispatch("Excel.Application")
excel.Visible = True
# Create a new workbook or open an existing one
workbook = excel.Workbooks.Add() # Creates a new workbook
# Access the first sheet
sheet = workbook.Sheets(1)
sheet.Name = "PyWin32_Example"
# Write some data to a cell
sheet.Cells(1, 1).Value = "Hello from pywin32!"
sheet.Cells(2, 1).Value = f"Current user: {os.environ.get('USERNAME', 'Unknown')}"
print("Excel automation complete. Check your Excel window.")
# To close Excel cleanly (optional, uncomment if desired)
# workbook.Close(SaveChanges=False)
# excel.Quit()
# del excel
# del workbook
# del sheet
Debug
Known issues
breaking`pypiwin32` (version 223) is a legacy package and has effectively been superseded by `pywin32`. Installing `pypiwin32` will pull in `pywin32`, but it's recommended to install `pywin32` directly for current versions and active maintenance.fixUse `pip install pywin32` instead of `pip install pypiwin32` for all new projects and consider updating existing projects.
affects: pypiwin32 versions <= 223
gotcha`pywin32` is a Windows-specific library and cannot be installed or run on non-Windows operating systems (like Linux or macOS). Attempts to install it elsewhere will fail.fixEnsure you are running Python on a Windows operating system.
affects: All versions
gotchaAfter installing `pywin32` (or indirectly `pypiwin32`), a post-installation script (`pywin32_postinstall.py`) might need to be run from an administrator command prompt to correctly register COM objects and DLLs, especially for global Python installations. This script should generally NOT be run inside virtual environments.fixRun `python -m pip install pywin32` (or `pypiwin32`), then if issues arise, navigate to your Python `Scripts` directory (e.g., `C:\PythonXX\Scripts`) and run `pywin32_postinstall.py -install` as an administrator. Avoid running this in virtual environments. For virtual environments, ensure `pywin32` DLLs are correctly symlinked or copied.
affects: All versions, especially when encountering `ModuleNotFoundError` for `pywintypes` or COM-related issues.
gotchaOlder versions of `pypiwin32` (like 223) may contain Python 2 syntax (e.g., `print "string"`) in their `setup.py` or other scripts. If pip attempts to build one of these old cached versions in a Python 3 environment, it will result in a `SyntaxError`.fixEnsure `pip` is configured to ignore cached versions or explicitly install `pywin32` directly to get a Python 3 compatible version. `pip install --no-cache-dir pywin32` can sometimes help.
affects: pypiwin32 <= 223 when installed with Python 3
gotchaThe `pywin32` project uses a simple incremental version numbering scheme, and any increase in the version number may correspond to a breaking interface change.fixIt is recommended that projects using `pywin32` pin the dependency to a specific version (e.g., `pywin32==311`) to avoid unexpected breaking changes.
affects: All versions of `pywin32`
Upgrade
Version history
223latest on PyPI · released Feb 26, 2018
Audit
Dependencies
pywin32required`pypiwin32` is a shim that depends on and installs `pywin32`.