Search code examples
pythonpython-3.6cx-freeze

cx_freeze "no module named" error when converting .py to .exe


I'm trying to convert .py file to .exe using cx_freeze and I get no errors while it's building. I tried it with another .py file and it worked perfectly, but this time, it gives me this error:

Traceback (most recent call last):
  File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 14, in run
    module.run()
  File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run
    exec(code, m.__dict__)
  File "borzacommercial.py", line 6, in <module>
  File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\bcrypt\__init__.py", line 25, in <module>
    from bcrypt import _bcrypt
ModuleNotFoundError: No module named '_cffi_backend'

What should I do?


Solution

  • When you get a message saying that part of a package is missing the first thing to do is to try adding the name of the missing package. You may get further errors which say that further modules are missing but just include those as well. You can do this by simply adding the name of the package in the packages option. Like this:

    from cx_Freeze import setup, Executable 
    
    base = None executables = [Executable("borzacommercial.py", base=base)] 
    
    packages = ["idna", "_cffi_backend"] 
    options = { 'build_exe': { 'packages':packages, }, } 
    
    setup( name = "<any name>", options = options, version = "<any number>", 
    description = '<any description>', executables = executables )