Search code examples
python-3.xwindowscx-freeze

Executable file created with cx_Freeze crashes on windows


I am trying to make an executable using cx_Freeze, it creates the exe, but whenever I try to launch it crashes with some error (see below).

setup.py:

from cx_Freeze import setup, Executable
import sys
import glob
import os
import zlib
import shutil

base = None
# PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = "C:\\ProgramData\\Anaconda3\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\ProgramData\\Anaconda3\\tcl\\tk8.6"
os.environ['TESSERACT_LIBRARY'] = "E:\\Tesseract-OCR"

if sys.platform == 'win32':
    base = "Win32GUI"

if sys.platform == 'win64':
    base = "Win64GUI"

include = [ 'jinja2', 'jinja2.ext',] #Include packages

includefiles = ['gui/']

options = {'build_exe':{'includes':include,'include_files': includefiles}}   

flaskapp = Executable(script="scan_config.py",
                       targetName="D2D.exe",
                   )

setup(
    name="D2D",
    version="1.0",
    author="abc",
    description="D2d",
    options={
        'build_exe': {
            'include_files': includefiles,
            'includes': include,
            'build_exe': "build"
        }
    },
    executables=[flaskapp]
)

Error:

Traceback (most recent call last): File "scan_config.py", line 5, in File "C:\Users\abc\AppData\Roaming\Python\Python37\site-packages\flask__init__.py", line 14, in from jinja2 import escape File "C:\ProgramData\Anaconda3\lib\site-packages\jinja2__init__.py", line 82, in _patch_async() File "C:\ProgramData\Anaconda3\lib\site-packages\jinja2__init__.py", line 78, in _patch_async from jinja2.asyncsupport import patch_all File "C:\ProgramData\Anaconda3\lib\site-packages\jinja2\asyncsupport.py", line 13, in import asyncio File "C:\ProgramData\Anaconda3\lib\asyncio__init__.py", line 8, in from .base_events import * File "C:\ProgramData\Anaconda3\lib\asyncio\base_events.py", line 37, in from . import constants ImportError: cannot import name 'constants' from 'asyncio' (E:\engine\build\lib\asyncio__init__.pyc)

P.S. I tried PyInstaller also, but I don't know how to include pytesseract.


Solution

  • I downgraded the python version to 3.6. That solved most of the errors. For jinja2 I did pip install https://github.com/pallets/jinja/zipball/master, and also included the mkl & libiomp5md files. In the multiprocessing folder I changed Pool.pyc to pool.pyc