Search code examples
pythoncx-freezem2crypto

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


I am trying to build an .exe file of my python script using cx_freeze. The problem that I am facing is as followed.

  1. cx_freeze is able to build the .exe file but during the build prints out messages that it cannot find certain modules. See part of the print out below.
    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. After the .exe file is build when I try to run it, I get the 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'

Can somebody explain to me how this error is caused and what I can do to resolve this?


Solution

  • I solved the issue by adding the libraries M2crypto and http to the setup options argument of cx_freeze. This includes the packages when building the .exe file

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