cx_freeze build .exe文件产生ModuleNotFoundError:没有名为'http.cookies'的模块

问题描述 投票:0回答:2

我正在尝试使用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'

有人可以向我解释此错误是如何引起的,以及如何解决该问题?

python cx-freeze m2crypto
2个回答
0
投票

[http.cookies是Python 3的每个安装中的基本库。如果您的程序找不到它,则Python 3的安装已损坏。


0
投票

我通过将库M2crypto和http添加到cx_freeze的setup options参数中解决了该问题。这包括构建.exe文件时的软件包

setup(name='x',
      version='0.1',
      description='xxx',
      options={"build_exe": {"packages": ["M2Crypto", "http"], "excludes": [""]}},
      executables=[Executable("x_script.py")])
© www.soinside.com 2019 - 2024. All rights reserved.