简体   繁体   中英

CX_Freeze import error on Windows and ZMQ

I've a python program that uses ZMQ. I want to Freeze it so everyone can use it as executable. This is my setup.py

import sys

from cx_Freeze import setup, Executable
includes = ["sip", "re", "zmq", "PyQt4.QtCore", "atexit", "zmq.utils.strtypes", "zmq.utils.jsonapi", "encodings.hex_codec"]

base = None
if sys.platform == "win32":
    base = "Win32GUI"

setup (
    name = "prueba",
    version = "0.1",
    description = "Esto es una prueba",
    options = {"build_exe" : {"includes" : includes }},
    executables = [Executable("Cliente.py", base = base)])

When I run this on Linux it works perfect and my program runs OK, but when I do so on Windows I get the Following Error when I execute the .exe file:

from zmq.core import (constants, error, message, context,
File "ExtensionLoader_zmq_core_error.py", line 12, in <module>
ImportError: DLL load failed: The specified module cannot be found

Also, when CX_Freeze is working I can notice the following lines: Missing modules: ? zmq.core.Context imported from zmq.devices.basedevice ? zmq.core.FORWARDER imported from zmq.devices.monitoredqueuedevice ? zmq.core.QUEUE imported from zmq.devices.monitoredquedevice ? zmq.core.ZMQError imported from zmq.devices.monitoredquedevice

I've been trying to figure out this problem for an hour or two, it seems it may be related with a DLL it should be importing and it isn't. Some DLL that ZMQ needs to work, but I cannot find which one is it.

Fixed by adding:

['zmq','zmq.utils.garbage','zmq.backend.cython']

To the packages, then renaming zmq.libzmq.pyd to libzmq.pyd

You may have to explicitly add one or more modules to your includes. If it IS a DLL issue though, I usually use Dependency Walker to figure it out. You can get it free here: http://www.dependencywalker.com/

It occasionally gave me a false positive, but overall it's almost always helped.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM