Search code examples
pythonwindowscx-freezepython-3.4pyzmq

What does this cx_Freeze error mean?


In trying to cx_Freeze a pyzmq-dependent Python 3.4 application on Windows 7, I am getting an exception when running the executable I can't make much sense of. The error, traceback edited for brevity, looks like this:

  Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\cx_freeze-4.3.3-py3.4-win32.egg\cx_Freeze\initscripts\Console.py", line 27, in <module>
    exec(code, m.__dict__)
  [...]
  File "Q:\Users\arvek\Repositories\accc-gui\aiozmq\aiozmq\__init__.py", line 4, in <module>
    import zmq
  File "C:\Python34\lib\importlib\_bootstrap.py", line 2237, in _find_and_load
    return _find_and_load_unlocked(name, import_)
  File "C:\Python34\lib\importlib\_bootstrap.py", line 2226, in _find_and_load_unlocked
    module = _SpecMethods(spec)._load_unlocked()
  File "C:\Python34\lib\importlib\_bootstrap.py", line 1191, in _load_unlocked
    return self._load_backward_compatible()
  File "C:\Python34\lib\importlib\_bootstrap.py", line 1161, in _load_backward_compatible
    spec.loader.load_module(spec.name)
  File "C:\Python34\lib\site-packages\zmq\__init__.py", line 49, in <module>
    from zmq.backend import *
  File "C:\Python34\lib\importlib\_bootstrap.py", line 2237, in _find_and_load
    return _find_and_load_unlocked(name, import_)
  File "C:\Python34\lib\importlib\_bootstrap.py", line 2226, in _find_and_load_unlocked
    module = _SpecMethods(spec)._load_unlocked()
  File "C:\Python34\lib\importlib\_bootstrap.py", line 1191, in _load_unlocked
    return self._load_backward_compatible()
  File "C:\Python34\lib\importlib\_bootstrap.py", line 1161, in _load_backward_compatible
    spec.loader.load_module(spec.name)
  File "C:\Python34\lib\site-packages\zmq\backend\__init__.py", line 41, in <module>
    reraise(*exc_info)
  File "C:\Python34\lib\site-packages\zmq\utils\sixcerpt.py", line 34, in reraise
    raise value
  File "C:\Python34\lib\site-packages\zmq\backend\__init__.py", line 29, in <module>
    _ns = select_backend(first)
  File "C:\Python34\lib\site-packages\zmq\backend\select.py", line 26, in select_backend
    mod = __import__(name, fromlist=public_api)
  File "C:\Python34\lib\importlib\_bootstrap.py", line 2237, in _find_and_load
    return _find_and_load_unlocked(name, import_)
  File "C:\Python34\lib\importlib\_bootstrap.py", line 2226, in _find_and_load_unlocked
    module = _SpecMethods(spec)._load_unlocked()
  File "C:\Python34\lib\importlib\_bootstrap.py", line 1191, in _load_unlocked
    return self._load_backward_compatible()
  File "C:\Python34\lib\importlib\_bootstrap.py", line 1161, in _load_backward_compatible
    spec.loader.load_module(spec.name)
  File "C:\Python34\lib\site-packages\zmq\backend\cython\__init__.py", line 6, in <module>
    from . import (constants, error, message, context,
  File "C:\Python34\lib\importlib\_bootstrap.py", line 2284, in _handle_fromlist
    _call_with_frames_removed(import_, from_name)
  File "C:\Python34\lib\importlib\_bootstrap.py", line 321, in _call_with_frames_removed
    return f(*args, **kwds)
  File "C:\Python34\lib\importlib\_bootstrap.py", line 2237, in _find_and_load
    return _find_and_load_unlocked(name, import_)
  File "C:\Python34\lib\importlib\_bootstrap.py", line 2226, in _find_and_load_unlocked
    module = _SpecMethods(spec)._load_unlocked()
  File "C:\Python34\lib\importlib\_bootstrap.py", line 1191, in _load_unlocked
    return self._load_backward_compatible()
  File "C:\Python34\lib\importlib\_bootstrap.py", line 1161, in _load_backward_compatible
    spec.loader.load_module(spec.name)
  File "ExtensionLoader_zmq_backend_cython_error.py", line 22, in <module>
  File "ExtensionLoader_zmq_backend_cython_error.py", line 14, in __bootstrap__
ImportError: DLL load failed: The specified module could not be found.

What's the specific cause of this error, i.e. which module (DLL I presume) is missing?


Solution

  • The hint lies in the following traceback entry:

    File "C:\Python34\lib\site-packages\zmq\backend\cython\__init__.py", line 6, in <module>
      from . import (constants, error, message, context,
    

    It doesn't give a direct answer to what's wrong, but does point towards the modules zmq.backend.cython.constants etc. being the problem, i.e. they are missing a DLL dependency. After checking with DependencyWalker, it turns out that 'C:\Python34\lib\site-packages\zmq\libzmq.pyd' is the DLL dependency in question. If that file is included with the frozen application, it works.