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.31k stars 214 forks source link

AttributeError on EL8 systems with Python 3.6.8 #1796

Closed davidsj2 closed 1 year ago

davidsj2 commented 1 year ago

OS: Red Hat Enterprise Linux release 8.7 (Ootpa Python: Python 3.6.8 (default, Oct 20 2022, 09:31:56) [GCC 8.5.0 20210514 (Red Hat 8.5.0-15)] on linux cx_Freeze version: 6.13.2 (plus older versions e.g. 6.11.1)

Note: this same issue was encountered by someone else here: https://stackoverflow.com/questions/73505683/attributeerror-module-hashlib-has-no-attribute-get-fips-mode

When building an executable using cx_Freeze, we see the following when invoking it:

Traceback (most recent call last):
  File "/disk01/user/dmcompiler/venv/lib/python3.6/site-packages/cx_Freeze/initscripts/__startup__.py", line 138, in run
    module_init.run(name + "__main__")
  File "/disk01/user/dmcompiler/venv/lib/python3.6/site-packages/cx_Freeze/initscripts/console.py", line 16, in run
    exec(code, module_main.__dict__)  # pylint: disable=exec-used
  File "dmcompiler/dmc.py", line 14, in <module>
  File "/disk01/user/dmcompiler/dmcompiler/structure.py", line 16, in <module>
    from pygccxml import declarations
  File "/disk01/user/dmcompiler/venv/lib/python3.6/site-packages/pygccxml/__init__.py", line 31, in <module>
    from . import declarations
  File "/disk01/user/dmcompiler/venv/lib/python3.6/site-packages/pygccxml/declarations/__init__.py", line 17, in <module>
    from .scopedef import scopedef_t
  File "/disk01/user/dmcompiler/venv/lib/python3.6/site-packages/pygccxml/declarations/scopedef.py", line 21, in <module>
    from .. import utils
  File "/disk01/user/dmcompiler/venv/lib/python3.6/site-packages/pygccxml/utils/__init__.py", line 11, in <module>
    from .utils import is_str
  File "/disk01/user/dmcompiler/venv/lib/python3.6/site-packages/pygccxml/utils/utils.py", line 12, in <module>
    import tempfile
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 656, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible
  File "/disk01/user/dmcompiler/venv/lib64/python3.6/tempfile.py", line 45, in <module>
    from random import Random as _Random
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 656, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible
  File "/disk01/user/dmcompiler/venv/lib64/python3.6/random.py", line 46, in <module>
    from hashlib import sha512 as _sha512
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 656, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible
  File "/disk01/user/dmcompiler/venv/lib64/python3.6/hashlib.py", line 219, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/disk01/user/dmcompiler/venv/lib64/python3.6/hashlib.py", line 124, in __get_openssl_constructor
    if not _hashlib.get_fips_mode():

Any ideas what could cause this?

marcelotduarte commented 1 year ago

Try this: pip uninstall -y cx_Freeze pip install --no-binary=cx_Freeze cx_Freeze

marcelotduarte commented 1 year ago

In fact, I've looked at the python source, and it could be that one (or more) modules aren't loading. Try using on the command line --includes=_sha256 python setup.py build_exe --includes=_sha256 or w/ cxfreeze ----includes=_sha256 ...

davidsj2 commented 1 year ago

Thanks; installing from source worked. Do you want me to try again with a binary wheel with flag?

marcelotduarte commented 1 year ago

Yes, please test.

davidsj2 commented 1 year ago

I'm running this from setup, so I I changed build_exe of options to look like:

build_exe_options = {
    'packages': ['inflection'],
    'include_files': ['dmcompiler/templates/'],
    'includes': ['_sha256']}

set in setup via: options = {'build_exe': build_exe_options},

I get the same stack trace with those updates when reverting back to binary wheel.

marcelotduarte commented 1 year ago

The binary wheels are made using CentOS7 (manylinux2014) and apparently have some issues with OpenSSL and FIPSMODE. As python 3.6 is EOL and from source worked, I'll close the issue.

GeekOffTheStreet commented 6 months ago

FWIW, this also happens on el8 with Python 3.8:

Traceback (most recent call last):
  File "/ssd/davidsj2/repos/dmcompiler/venv38/lib/python3.8/site-packages/cx_Freeze/initscripts/__startup__.py", line 124, in run
    module_init.run(name + "__main__")
  File "/ssd/davidsj2/repos/dmcompiler/venv38/lib/python3.8/site-packages/cx_Freeze/initscripts/console.py", line 16, in run
    exec(code, module_main.__dict__)
  File "dmcompiler/dmc.py", line 14, in <module>
    import dmcompiler.structure as structure
  File "/ssd/davidsj2/repos/dmcompiler/dmcompiler/structure.py", line 19, in <module>
    from pygccxml import declarations
  File "/ssd/davidsj2/repos/dmcompiler/venv38/lib/python3.8/site-packages/pygccxml/__init__.py", line 33, in <module>
    from . import parser
  File "/ssd/davidsj2/repos/dmcompiler/venv38/lib/python3.8/site-packages/pygccxml/parser/__init__.py", line 12, in <module>
    from .project_reader import COMPILATION_MODE
  File "/ssd/davidsj2/repos/dmcompiler/venv38/lib/python3.8/site-packages/pygccxml/parser/project_reader.py", line 11, in <module>
    from . import source_reader
  File "/ssd/davidsj2/repos/dmcompiler/venv38/lib/python3.8/site-packages/pygccxml/parser/source_reader.py", line 15, in <module>
    from . import declarations_cache
  File "/ssd/davidsj2/repos/dmcompiler/venv38/lib/python3.8/site-packages/pygccxml/parser/declarations_cache.py", line 8, in <module>
    import hashlib
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 618, in _load_backward_compatible
  File "<frozen zipimport>", line 259, in load_module
  File "/ssd/davidsj2/repos/dmcompiler/venv38/lib64/python3.8/hashlib.py", line 218, in <module>
    if not _hashlib.get_fips_mode():
AttributeError: module '_hashlib' has no attribute 'get_fips_mode'

Seems like it's Red Hat patched in el8+ systems: https://bugzilla.redhat.com/show_bug.cgi?format=multiple&id=1745685 https://raw.githubusercontent.com/openela-main/python3/352f011d1bb441e4f8fcf20da041780254486597/SOURCES/00329-fips.patch