1. Anthony Tuininga
  2. cx_Freeze
  3. Pull requests

Pull requests

#18 Merged at e797853
Repository
takluyver
Branch
fix-re-py3
Repository
anthony_tuininga
Branch
default

Ensure re module is copied on Python 3

Author
  1. Thomas Kluyver
Reviewers
Description

This fixes a bug that I've been hearing about for a while - programs frozen with Python 3 fail with an ImportError trying to load re.

What's going on: ModuleFinder._AddBaseModules ensures that a handful of essential modules are always copied, like the traceback module. While reading those, it excludes certain other modules that would otherwise be found by scanning the base modules' code. In Python 2, re could safely be excluded, but in Python 3, linecache requires tokenize, which imports re.

This has two symptoms:

  1. If the user's code only has import trails to re via the base modules, the base modules aren't re-scanned for imports, so re isn't copied, and an ImportError pops up. For instance, this traceback shows the import trail random -> warnings (base module) -> linecache -> tokenize -> re.

  2. If the user's code has no import trail to re, but fails with another error, and they are using Win32GUI, the traceback can't be created because the traceback module fails to import re.

The fix is simple - on Python 3, we allow the base modules to trigger copying of re.

Comments (0)