AttributeError: NoneType has no attribute 'utf_8_decode'

Issue #285 resolved
Jason R. Coombs
created an issue

With 0.6.25, the script launchers were updated to be loaded from the package (so they could be converted to Python 3 during the package conversion). However, this also meant that they needed to be decoded to unicode when loaded.

The simple act of invoking ''.decode in distribute gives rise in some cases to an AttributeError. The underlying issue is that a module (such as encodings.utf_8) will be finalized (have its globals set to None) if it is removed from sys.modules.

Due to the way the setuptools.sandbox works, if encodings.utf_8 was not in the globals when the sandbox is created (often before the user's is invoked), it will be removed from sys.modules and will cause subsequent invocations of ''.decode('utf-8') to fail.

Distribute should be more careful about which modules it removes, at least in the encodings.

Comments (3)

  1. Jason R. Coombs reporter

    This script will generally reproduce the issue:

    import setuptools.command.easy_install
    setup_params = dict(
    if __name__ == '__main__':

    It causes the failure (if invoked using easy_install) because

    • It invokes ''.decode('utf-8') sometime after the sandbox is created.
    • It depends on a project that installs scripts.

    Note that it doesn't _always_ fail. It depends on a race condition (does the garbage collector clean up utf_8 before the scripts are processed).

  2. Log in to comment