The problem with cx_Freeze when compiling in exe. If there is an import of some library in the code, for example openpyxl (I work with reading and writing Office documents), then the exe file opens the window that I painted, but falls after trying to open the excel file (this function hangs on a separate button in the GUI window and launches a piece of code with openpyxl).
I work in PyCharm, as I understand it automatically creates a venv for my project. I install all third-party libraries through it, in File - Settings - Project: Excel - Project Interpreter. The code works fine in PyCharme.
If the source code instead of importing openpyxl put a stub, then the compiled binary works.
After compilation, the empty folder is not built in build_windows \ lib \ openpyxl The library itself seems to be copied.
What could be the problem, where to dig?
setup.py file code:
from cx_Freeze import setup, Executable executables = [Executable('superMain.py', targetName='Calculator.exe', base='Win32GUI', icon='it.ico')] excludes = ['logging', 'unittest', 'email', 'html', 'http', 'urllib', 'xml', 'unicodedata', 'bz2', 'select'] options = { 'build_exe': { 'include_msvcr': True, 'excludes': excludes, 'build_exe': 'build_windows', } } setup(name='Калькулятор конструкций', version='0.0.1', description='Учебная программа', executables=executables, options=options)
The code that runs on the button and causes a crash:
from openpyxl import load_workbook from open_patch_file import wb_patch # переменная содержит путь до книги name_column = 3 #Столбец с наименованием сортамента qant_column = 4 #Столбец с колличеством length_column = 5 #Столбец с длиной start_row = 2 #Строка с которой начинаются данные wb = load_workbook(wb_patch) sheet = wb.active xer = 1 # Поиск разрывов в таблице из пустых строк while sheet.cell(row=xer, column=name_column).value is not None \ or sheet.cell(row=xer, column=qant_column).value is not None\ or sheet.cell(row=xer, column=length_column).value is not None: xer = xer + 1 sortament = {} for i in range(start_row, xer): if sheet.cell(row=i, column=name_column).value == None: # Проверка на пустые строки sheet.cell(row=i, column=name_column).value = 'Пустая строка' sort = sheet.cell(row=i, column=name_column).value.replace("\n", "").strip() # Удаляем \n оставшихся от экселя и обрезаем через strip лишние пробелы по концам if sheet.cell(row=i, column=length_column).value == None or type( sheet.cell(row=i, column=length_column).value) == str: # Проверка на пустые строки или лажу в графе "длина" sheet.cell(row=i, column=length_column).value = 0 length = sheet.cell(row=i, column=qant_column).value * sheet.cell(row=i, column=length_column).value / 1000 sortament[i - 2] = tuple((sort, round(length, 3))) rezult_calc = {} for y in sortament: sort_name = sortament[y][0] if sort_name in rezult_calc: rezult_calc[sort_name] += sortament[y][1] else: rezult_calc[sort_name] = sortament[y][1]
build_exe_options
for example, only with your module: cx-freeze.readthedocs.io/en/latest/… . There arepackages
andincludes
options. Perhaps you need to manually register them. I would also recommend trying to run your script separately from the command line without PyCharm participation. - Bogdan