{"id":3764,"library":"pypiwin32","title":"Python for Windows Extensions (via pypiwin32 shim)","description":"pypiwin32 is a legacy shim package that facilitated installation of the `pywin32` project on older Python versions. The core `pywin32` extensions provide comprehensive access to many Windows APIs from Python, including COM automation, Windows services, and GUI programming. While `pypiwin32` itself is no longer actively developed (last released 2018), it still serves as a dependency for projects that might not have updated their requirements. The underlying `pywin32` project is actively maintained, with frequent releases. The current latest version of the actual `pywin32` project is 311, released on July 14, 2025.","status":"deprecated","version":"223","language":"en","source_language":"en","source_url":"https://github.com/mhammond/pywin32","tags":["windows","win32","COM","API","system","automation","GUI"],"install":[{"cmd":"pip install pypiwin32","lang":"bash","label":"Install pypiwin32 (indirectly installs pywin32)"},{"cmd":"pip install pywin32","lang":"bash","label":"Recommended: Install pywin32 directly"}],"dependencies":[{"reason":"`pypiwin32` is a shim that depends on and installs `pywin32`.","package":"pywin32","optional":false}],"imports":[{"symbol":"win32api","correct":"import win32api"},{"symbol":"win32con","correct":"import win32con"},{"symbol":"win32gui","correct":"import win32gui"},{"symbol":"win32com.client","correct":"import win32com.client"},{"note":"While `pywintypes` might be found in a `win32` subdirectory in site-packages, the direct import is standard.","wrong":"from win32 import pywintypes","symbol":"pywintypes","correct":"import pywintypes"}],"quickstart":{"code":"import win32com.client\nimport os\n\n# This example demonstrates interacting with Microsoft Excel via COM.\n# Ensure Excel is installed on the system.\n\ntry:\n    # Attempt to get an existing Excel application\n    excel = win32com.client.GetActiveObject(\"Excel.Application\")\nexcept:\n    # If no active Excel instance, create a new one\n    excel = win32com.client.Dispatch(\"Excel.Application\")\n\nexcel.Visible = True\n\n# Create a new workbook or open an existing one\nworkbook = excel.Workbooks.Add() # Creates a new workbook\n\n# Access the first sheet\nsheet = workbook.Sheets(1)\nsheet.Name = \"PyWin32_Example\"\n\n# Write some data to a cell\nsheet.Cells(1, 1).Value = \"Hello from pywin32!\"\nsheet.Cells(2, 1).Value = f\"Current user: {os.environ.get('USERNAME', 'Unknown')}\"\n\nprint(\"Excel automation complete. Check your Excel window.\")\n\n# To close Excel cleanly (optional, uncomment if desired)\n# workbook.Close(SaveChanges=False)\n# excel.Quit()\n# del excel\n# del workbook\n# del sheet","lang":"python","description":"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."},"warnings":[{"fix":"Use `pip install pywin32` instead of `pip install pypiwin32` for all new projects and consider updating existing projects.","message":"`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.","severity":"breaking","affected_versions":"pypiwin32 versions <= 223"},{"fix":"Ensure you are running Python on a Windows operating system.","message":"`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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Run `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.","message":"After 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.","severity":"gotcha","affected_versions":"All versions, especially when encountering `ModuleNotFoundError` for `pywintypes` or COM-related issues."},{"fix":"Ensure `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.","message":"Older 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`.","severity":"gotcha","affected_versions":"pypiwin32 <= 223 when installed with Python 3"},{"fix":"It is recommended that projects using `pywin32` pin the dependency to a specific version (e.g., `pywin32==311`) to avoid unexpected breaking changes.","message":"The `pywin32` project uses a simple incremental version numbering scheme, and any increase in the version number may correspond to a breaking interface change.","severity":"gotcha","affected_versions":"All versions of `pywin32`"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}