I have problems running a compiled program with win32print and win32ui (to print an image) on a different computer.
what shall i do?

Dani AI

Generated

A short explanation and a practical fix.

pywin32 extensions like win32print and win32ui are compiled C extensions that also rely on runtime DLLs (pythoncom/pywintypes and the Visual C++ runtime). py2exe can miss them because pywin32 uses dynamic imports and COM codegen. The reliable approach is to force py2exe to bundle the modules and make sure the native DLLs are present in the dist folder.

A minimal setup.py pattern that usually works:

from distutils.core import setup
import py2exe

setup(
    windows=[{'script': 'myapp.py'}],
    options={
        'py2exe': {
            'includes': ['win32print', 'win32ui', 'win32api', 'win32con'],
            'packages': ['win32com'],
            'zipfile': None
        }
    }
)

After building, verify the dist folder contains the extension modules and DLLs: win32print.pyd, win32ui.pyd, and the pywin32 DLLs named like pythoncomXY.dll and pywintypesXY.dll (XY = Python major/minor). If any are missing, copy them from the Python installation (search site-packages for pywin32_system32 or win32). Also ensure the target machine has the correct Visual C++ redistributable for the Python build (missing VC runtime causes DLL load failures that surface as import errors).

Troubleshooting tips: run the exe from a console to capture the full traceback; look for "DLL load failed" vs "No module named" to tell if a native dependency is missing; Dependency Walker or similar tools can reveal missing native DLLs. As noted, manually copying files can prove the cause, and as suggested, GUI tools can generate setup templates—however forcing includes/packages and copying the pywin32 DLLs is the usual fix. See py2exe and pywin32 documentation for details: py2exe and pywin32.

Recommended Answers

All 4 Replies

Do you get any error message? There should be a log file if you get an error while running the executable.

Yeah, its sayin, there wouldnt be the module win32print, although it worked as py file

Maybe you should just search for the module win32print and put it in the same directory as the executable. Thats what i would do. I know there are more complicated py2exe scripts that include these kind of things, you could look into those as well.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.