marcelotduarte / cx_Freeze

cx_Freeze creates standalone executables from Python scripts, with the same performance, is cross-platform and should work on any platform that Python itself works on.
https://marcelotduarte.github.io/cx_Freeze/
Other
1.33k stars 217 forks source link

MKL hook trigger an error during setup #2449

Closed donsylvano closed 3 months ago

donsylvano commented 3 months ago

Problem encountered During execution of my setup.py, the following error is thrown, after a long list of calls:

File "C:...\miniconda3\envs\testenv\Lib\site-packages\cx_Freeze\hooks\mkl.py", line 29, in load_mkl if distribution.installer == "pip": AttributeError: 'NoneType' object has no attribute 'installer'

The fact that disabling the load_mkl function solved the problem indicates that there may be a bug in the mkl hook.

To Reproduce I created a fresh conda environnement using miniconda. My script is very short, but it needs pandas, therefore numpy and mkl, as dependecies.

Expected behavior As far as I understand, the hooks are there to help with importing specific libraries. In this case it seems to add a bug. I found the following workaround for my specific situation:

Workaround After commenting out the code of the load_mkl function in hooks/mkl.py, the setup is able to create the .exe without any errors, and the resulting program runs successfully.

Desktop

setup.py `# -- coding: latin-1 --

from cx_Freeze import setup, Executable

import glob import os import sys import shutil

includes = ['numpy','pandas','mkl'] excludes = [] packages = ['numpy', 'pandas', 'mkl'] bin_excludes = [] include_files=['test.csv']

build_exe_options = { "optimize": 0, "includes": includes, "excludes": excludes, "packages": packages, "include_files": include_files, "bin_excludes": bin_excludes }

setup( name="bs_json", version="1.0", description = "Read JSON from file", options = {"build_exe": build_exe_options}, executables = [Executable("bs_json.py", base=None)] )`

Footnote This is my first issue report on GitHub. Any constructive feedback welcome

marcelotduarte commented 3 months ago

Hi! Change the line that throws the error: if distribution.installer == "pip": by if distribution and distribution.installer == "pip" and give a feedback. I should publish the fix soon.

Sometimes the guy just says 'there was an error', and doesn't even include the long traceback. I want to fix it, but without information it's difficult. As for you, you went to the trouble of finding a workaround. That is great.

donsylvano commented 3 months ago

Hello, All good! After changing the line as mentioned, no more exception and the setup succeeded. Thanks for the quick response and for the feedback.

marcelotduarte commented 3 months ago

Release 7.1.1 is out! Documentation