Skip to content

How to Fix Python py2exe Build Error

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about How to Fix Python py2exe Build Error. We cover key concepts, practical examples, and best practices.

Py2exe fails to build Windows executables when the build script is missing required options, MSVCR90.dll is not included, or the Python installation is not for Windows.

The Wrong Way

# setup.py
from distutils.core import setup
import py2exe

setup(
    windows=[{"script": "myscript.py"}],
)

Building:

python setup.py py2exe

Output:

error: MSVCP90.dll: No such file or directory

The Right Way

# setup.py
from distutils.core import setup
import py2exe

setup(
    windows=[{"script": "myscript.py"}],
    options={
        "py2exe": {
            "includes": ["os", "sys", "json"],
            "excludes": ["tkinter"],
            "dll_excludes": ["MSVCP90.dll"],
            "bundle_files": 1,
            "compressed": True,
        }
    },
    zipfile=None,
)

Build:

python setup.py py2exe

The executable is created in the dist folder.

Prevention Tips

  • Use py2exe only on Windows. It does not work on Linux or macOS.
  • Use dll_excludes to skip missing DLLs.
  • Set bundle_files=1 for a single executable.
  • Set compressed=True to reduce file size.
  • Test the executable on a Windows machine without Python.

Common Mistakes with py2exe

  1. Non-exhaustive pattern matches that compile with warnings then crash at runtime
  2. Misunderstanding that String is [Char] with poor performance for large text operations
  3. Using foldl instead of foldl' causing stack overflow on large lists

These mistakes appear frequently in real-world PYTHON code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### What is the difference between py2exe and PyInstaller?

py2exe is Windows-only and older. PyInstaller is cross-platform and actively maintained. Use PyInstaller for new projects. py2exe may be needed for legacy applications.

Why does py2exe fail with "MSVCP90.dll not found"?

The Visual C++ redistributable is missing. Install the VC++ 2008 redistributable. Alternatively, exclude the DLL with dll_excludes if your application does not need it.

Can I create a 64-bit executable with py2exe?

py2exe creates executables matching your Python architecture. Use a 64-bit Python installation to create 64-bit executables. py2exe does not support cross-compilation.

Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro