cx_freeze build .exe file produces ModuleNotFoundError: No module named 'http.cookies'

cx_freeze build .exe file produces ModuleNotFoundError: No module named 'http.cookies'

我正在尝试使用 cx_freeze 构建我的 python 脚本的 .exe 文件。 我面临的问题如下。

  1. cx_freeze 能够构建 .exe 文件,但在构建过程中打印出找不到某些模块的消息。请参阅下面的部分打印件。
    Missing modules:
    ? M2Crypto.six.moves.http_client imported from M2Crypto.httpslib
    ? M2Crypto.six.moves.http_cookies imported from M2Crypto.AuthCookie
    ? M2Crypto.six.moves.socketserver imported from M2Crypto.SSL.SSLServer
    ? M2Crypto.six.moves.urllib_parse imported from M2Crypto.httpslib, M2Crypto.m2urllib2
    ? M2Crypto.six.moves.urllib_response imported from M2Crypto.m2urllib, M2Crypto.m2urllib2
    ? M2Crypto.six.moves.xmlrpc_client imported from M2Crypto.m2xmlrpclib
    ? StringIO imported from M2Crypto.six
    ? _builtin_ imported from M2Crypto.m2crypto
    ? _main_ imported from bdb, pdb
    ? _frozen_importlib imported from importlib, importlib.abc
    ? _frozen_importlib_external imported from importlib, importlib._bootstrap, importlib.abc
    ? _m2crypto imported from M2Crypto.m2crypto
    ? _posixsubprocess imported from subprocess
    ? _scproxy imported from urllib.request
    ? _winreg imported from platform
    ? grp imported from shutil, tarfile
    ? java.lang imported from platform
    ? org.python.core imported from copy, pickle
    ? os.path imported from M2Crypto.m2crypto, os, pkgutil, py_compile, tracemalloc, unittest, unittest.util
    ? posix imported from os
    ? pwd imported from getpass, http.server, netrc, posixpath, shutil, tarfile, webbrowser
    ? termios imported from getpass, tty
    ? twisted.internet.interfaces imported from M2Crypto.SSL.TwistedProtocolWrapper
    ? twisted.internet.reactor imported from M2Crypto.SSL.TwistedProtocolWrapper
    ? twisted.protocols.policies imported from M2Crypto.SSL.TwistedProtocolWrapper
    ? urllib2 imported from M2Crypto.m2urllib2
    ? vms_lib imported from platform
    ? xmlrpclib imported from M2Crypto.m2xmlrpclib
    ? zope.interface imported from M2Crypto.SSL.TwistedProtocolWrapper
This is not necessarily a problem - the modules may not be needed on this platform.
  1. 当我尝试 运行 构建 .exe 文件后,我得到 ModuleNotFoundError
    Traceback (most recent call last):
      File "C:\Users\masta\Miniconda3\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 40, in run
        module.run()
      File "C:\Users\masta\Miniconda3\lib\site-packages\cx_Freeze\initscripts\Console.py", line 23, in run
        exec(code, {'_name_': '_main_'})
      File "decrypt_verify.py", line 3, in <module>
      File "C:\Users\masta\Miniconda3\lib\site-packages\M2Crypto\__init__.py", line 30, in <module>
        from M2Crypto import (ASN1, AuthCookie, BIO, BN, DH, DSA, EVP, Engine, Err,
      File "C:\Users\masta\Miniconda3\lib\site-packages\M2Crypto\AuthCookie.py", line 12, in <module>
        from M2Crypto.six.moves.http_cookies import SimpleCookie  # pylint: disable=no-name-in-module,import-error
      File "C:\Users\masta\Miniconda3\lib\site-packages\M2Crypto\six.py", line 203, in load_module
        mod = mod._resolve()
      File "C:\Users\masta\Miniconda3\lib\site-packages\M2Crypto\six.py", line 115, in _resolve
        return _import_module(self.mod)
      File "C:\Users\masta\Miniconda3\lib\site-packages\M2Crypto\six.py", line 82, in _import_module
        __import__(name)
    ModuleNotFoundError: No module named 'http.cookies'

有人可以向我解释这个错误是如何引起的吗?我可以做些什么来解决这个问题?

http.cookies是每次安装Python3的基础库,如果你的程序找不到,说明你安装的Python3坏了。

我通过将库 M2crypto 和 http 添加到 cx_freeze 的设置选项参数中解决了这个问题。这包括构建 .exe 文件时的包

setup(name='x',
      version='0.1',
      description='xxx',
      options={"build_exe": {"packages": ["M2Crypto", "http"], "excludes": [""]}},
      executables=[Executable("x_script.py")])