Search code examples
pythonbeautifulsoupcx-freeze

cx-freeze not able to build python containing urllib and bs4


I have made a script in python using urllib abd bs4 and i want to make it executable using cx-freeze.But I am not able to do it. It shows the following error:

Missing modules:
? Carbon imported from plistlib
? Carbon.File imported from plistlib
? Carbon.Files imported from plistlib
? MacOS imported from platform
? OpenSSL.SSL imported from requests.packages.urllib3.contrib.pyopenssl
? _dummy_threading imported from dummy_threading
? _emx_link imported from os
? _scproxy imported from urllib
? bs4.builder imported from bs4
? builtins imported from requests.packages.urllib3.packages.six
? cchardet imported from bs4.dammit
? ce imported from os
? chardet imported from bs4.dammit
? fcntl imported from subprocess
? gestalt imported from platform
? http imported from requests.compat
? http.client imported from requests.packages.urllib3.connectionpool
? http.cookies imported from requests.compat
? iconv_codec imported from bs4.dammit
? java.lang imported from platform
? ndg.httpsclient.ssl_peer_verification imported from requests.packages.urllib3.
contrib.pyopenssl
? ndg.httpsclient.subj_alt_name imported from requests.packages.urllib3.contrib.
pyopenssl
? netbios imported from uuid
? org.python.core imported from copy, pickle
? os.path imported from os, requests.certs, shlex
? os2 imported from os
? os2emxpath imported from os
? posix imported from os
? pwd imported from getpass, posixpath
? pyasn1.codec.der imported from requests.packages.urllib3.contrib.pyopenssl
? queue imported from requests.packages.urllib3.connectionpool
? riscos imported from os
? riscosenviron imported from os
? riscospath imported from os
? rourl2path imported from urllib
? simplejson imported from requests.compat
? termios imported from getpass
? urllib.parse imported from requests.compat, requests.packages.urllib3.request
? urllib.request imported from requests.compat
? vms_lib imported from platform
? win32api imported from platform
? win32con imported from platform
? win32pipe imported from platform
? win32wnet imported from uuid
This is not necessarily a problem - the modules may not be needed on this platfo
rm.

I have imported bs4, requests, re, time in my program. What should I do?


Solution

  • If builds fail because they aren't automatically including imported libraries you can add them into the package section of your setup.py. See this post.

    setup.py

    import sys
    from cx_Freeze import setup, Executable
    
    # Dependencies are automatically detected, but it might need fine tuning.
    build_exe_options = {"packages": ["bs4, urllib, requests"], "excludes": [""]}
    
    # GUI applications require a different base on Windows (the default is for a
    # console application).
    base = None
    if sys.platform == "win32":
        base = "Win32GUI"
    
    setup(  name = "my-app",
            version = "0.9.0",
            description = "Copyright 2013",
            options = {"build_exe": build_exe_options},
            executables = [Executable("my_module.py", base=base)])
    

    You likely might only have to specify bs4, most modules should be found and included automatically. BS4 is known to have issues? so just try including that at first.

    here is the docs for cx_freeze.