1

I'm using python 3.7 and cx_Freeze 5.1.1 , I'm, trying to convert my python script into an executable but I am getting thrown a missing module error and I am stumped.

I have tried putting the modules in the package and includes of the setup script but nothing is changing.

import sys
from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need fine tuning.
# build_exe_options = {"packages": ["os", "win32api", "win32con", "pywintypes", "easyguy", "ntsecuritycon"
#    , "win32security", "errno", "shutil", "ctypes"], "excludes": ["tkinter"],
#                     "includes" = ['easy_gui']}

build_exe_options = {'packages': ['sys', "os", "win32api", "win32con", 
                                  "pywintypes", "easygui", "ntsecuritycon",
                                  "errno", "shutil", "ctypes", "win32security", 
                                  "errno", "shutil", "ctypes"],
                     'excludes': ['tkinter'],
                     'includes': ["os", "win32api", "win32con", "pywintypes", 
                                  "easygui", "ntsecuritycon",
                                  "errno", "shutil", "ctypes", "win32security", 
                                  "errno", "shutil", "ctypes"]}

# 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="Automated Installer",  # this will set the name of the created executable to "Automated Installer.exe"
      version="0.1",
      description="My GUI application!",
      options={"build_exe": build_exe_options},
      executables=[Executable("Automated Installer.py", base=base)])  # this tells cx_Freeze to freeze the script "Automated Installer.py"

I expect a executable to be created, instead I am thrown this error\

ImportError: No module named 'win32api'

EDIT 2: Reflecting Steps taken by the answer posted below.

I upgraded back to Python 3.7 and I applied the fix to freezer.py as recommended. I took the exact same easygui script written and the same setup.py script also written below. The executable builds, but does not run. I am thrown an error shown below. I am able to run the example easygui script just fine, so that leads me to believe that easygui is installed correctly.

Error popup when executable created is run

I'm not too sure what you mean by the full stack trace but here is some notable output from the command prompt that I received

Missing modules:
? __main__ imported from bdb, pdb 
? _frozen_importlib imported from importlib, importlib.abc
? _frozen_importlib_external imported from importlib, importlib._bootstrap, 
importlib.abc
? _posixsubprocess imported from subprocess
? _winreg imported from platform
? easygui imported from hello world__main__
? grp imported from shutil, tarfile
? java.lang imported from platform
? org.python.core imported from copy, pickle
? os.path imported from os, pkgutil, py_compile, tracemalloc, unittest, 
unittest.util
? posix imported from os
? pwd imported from http.server, posixpath, shutil, tarfile, webbrowser
? termios imported from tty
? vms_lib imported from platform
This is not necessarily a problem - the modules may not be needed on this 
platform.

running build
running build_exe
copying C:\Users\Billy\AppData\Local\Programs\Python\Python37\lib\site-                                        
packages\cx_Freeze\bases\Win32GUI.exe -> build\exe.win-amd64-3.7\hello 
world.exe
copying 
C:\Users\Billy\AppData\Local\Programs\Python\Python37\python37.dll -> 
build\exe.win-amd64-3.7\python37.dll
copying 
C:\Users\Billy\AppData\Local\Programs\Python\Python37\VCRUNTIME140.dll -> 
build\exe.win-amd64-3.7\VCRUNTIME140.dll
copying C:\Program Files\TortoiseGit\bin\api-ms-win-crt-runtime-l1-1-0.dll - 
> 
build\exe.win-amd64-3.7\api-ms-win-crt-runtime-l1-1-0.dll
copying C:\Program Files\TortoiseGit\bin\api-ms-win-crt-stdio-l1-1-0.dll -> 
build\exe.win-amd64-3.7\api-ms-win-crt-stdio-l1-1-0.dll
copying C:\Program Files\TortoiseGit\bin\api-ms-win-crt-math-l1-1-0.dll -> 
build\exe.win-amd64-3.7\api-ms-win-crt-math-l1-1-0.dll
copying C:\Program Files\TortoiseGit\bin\api-ms-win-crt-locale-l1-1-0.dll -> 
build\exe.win-amd64-3.7\api-ms-win-crt-locale-l1-1-0.dll
copying C:\Program Files\TortoiseGit\bin\api-ms-win-crt-heap-l1-1-0.dll -> 
build\exe.win-amd64-3.7\api-ms-win-crt-heap-l1-1-0.dll
*** WARNING *** unable to create version resource
install pywin32 extensions first
writing zip file build\exe.win-amd64-3.7\lib\library.zip
BChiu
  • 69
  • 1
  • 10
  • I'v tried to fix the indentation of your code, can you please confirm that it is correct now, or fix further? You still have unnecessary entries in the `build_exe` options. – jpeg Feb 07 '19 at 07:11

1 Answers1

1
  1. cx_Freeze does not yet support Python 3.7, it has a bug. A bugfix exists but has not yet been released, however you can apply it manually, see What could be the reason for fatal python error:initfsencoding:unable to load the file system codec? and Cx_freeze crashing Python3.7.0. Or you can rollback to Python 3.6 if this is an option for you.

EDIT:

  1. Check that easygui is correctly installed. You should for example be able to run the following hello.py example script from the easygui documentation:

    from easygui import *
    import sys
    
    # A nice welcome message
    ret_val = msgbox("Hello, World!")
    if ret_val is None: # User closed msgbox
        sys.exit(0)
    
    msg = "What is your favorite flavor?\nOr Press <cancel> to exit."
    title = "Ice Cream Survey"
    choices = ["Vanilla", "Chocolate", "Strawberry", "Rocky Road"]
    while 1:
        choice = choicebox(msg, title, choices)
        if choice is None:
            sys.exit(0)
        msgbox("You chose: {}".format(choice), "Survey Result")
    
  2. Try to freeze this example script. easygui depends on tkinter, which requires some additional tuning to be frozen with cx_Freeze 5.1.1, see tkinter program compiles with cx_Freeze but program will not launch. You should be able to freeze the example using the following setup script:

    from cx_Freeze import setup, Executable
    import os
    import sys
    
    PYTHON_INSTALL_DIR = os.path.dirname(sys.executable)
    os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
    os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
    
    build_exe_options = {'include_files': [(os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
                                            os.path.join('lib', 'tk86t.dll')),
                                           (os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'),
                                            os.path.join('lib', 'tcl86t.dll'))]}
    
    # 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='hello',
          version='0.1',
          description='Sample cx_Freeze EasyGUI script',
          executables=[Executable('hello.py', base=base)],
          options={'build_exe': build_exe_options})
    
jpeg
  • 2,372
  • 4
  • 18
  • 31
  • I made a simpler setup.py that has only easygui as part of includes and packages, and I rolled back my python to 3.6.8. When I ran python setup.py build, I still got `ImportError: No module named 'easygui'` – BChiu Feb 07 '19 at 18:47
  • @BChiu I've edited my answer accordingly. If you still have problems with this example, please post the complete error message including the full stack trace. – jpeg Feb 08 '19 at 07:05
  • I'm confused as to what the differences between includes and packages are in my original setup.py, Is there anything wrong with my setup,py that could lead to an missing module error? I have adjusted the original question to reflect the current steps I have taken. I also noted that you don't have a packages option in your `build_exe_options` – BChiu Feb 08 '19 at 16:17
  • @BChiu As far as the difference between `includes` and `packages` is concerned, see the `cx_Freeze` [documentation](https://cx-freeze.readthedocs.io/en/latest/distutils.html#build-exe). I'm able to run the example script of my answer frozen with the setup script of my answer with python 3.6 and `cx_Freeze` 5.1.1. Try to rollback to python 3.6 and upgrade all packages to the latest version. If it still does not work I unfortunately don't know how to help further. – jpeg Feb 11 '19 at 07:41
  • @BChiu Maybe try to add `'packages': ['tkinter', 'easygui']` to the `build_exe_options` dictionary. – jpeg Feb 11 '19 at 07:43
  • @BChiu One more question: are you using the **same** python installation to run the unfrozen script and to freeze it with `cx_Freeze`? – jpeg Feb 11 '19 at 07:45