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.28k stars 210 forks source link

pack one complex project with many model raise RecursionError: maximum recursion depth exceeded #2273

Open WoolenWang opened 4 months ago

WoolenWang commented 4 months ago

Prerequisite

Describe the bug A clear and concise description of what the bug is.

when i pack a complex project with many model like :

build_exe_options:{'build_exe': 'build/woolen_quant_client', 'packages': ['pypinyin', 'itsdangerous', 'woolen_alpha_tool', 'flask_socketio', 'netifaces', 'woolen_quant', 'flask_inputs', 'setproctitle', 'pympler', 'marshmallow', 'idna.idnadata', 'flask_mail', 'socketio', 'watchdog', 'fastcache', 'dns', 'flask_compress', 'email_validator', 'simplejson', 'cython', 'woolen_alpha', 'logbook', 'woolen_data_source', 'markupsafe', 'lxml', 'engineio', 'pandas', 'numpy', 'eventlet', 'flask_security', 'certifi', 'cpuinfo', 'tkinter', 'py_help', 'prettytable', 'sentry_sdk', 'paramiko', 'flask', 'cached_property', 'flask_login', 'woolen_trade_broker', 'passlib', 'flask_wtf', 'flask_migrate', 'rpyc', 'apscheduler', 'pyzipper', 'flask_sqlalchemy', 'six', 'matplotlib', 'chardet', 'woolen_config', 'logging.config', 'sqlalchemy', 'pkg_resources', 'flask_script', 'pystray', 'better_exceptions', 'flask_cors', 'Cryptodome', 'pydantic', 'wrapt', 'flask_admin', 'psutil', 'flask_restful', 'flask_swagger_ui', 'cytoolz', 'talib', 'flask_babel', 'statsmodels', 'toolz', 'asyncio', 'jinja2', 'scipy', 'pysqlcipher3', 'seaborn', 'werkzeug', 'woolen_sim_trade'], 'include_files': ['web_ui/static.zip', 'config/', 'pkg_data/7z.exe', 'pkg_data/bash.exe', 'pkg_data/certmgr.exe', 'pkg_data/grep.exe', 'pkg_data/gzip.exe', 'pkg_data/install.bat', 'pkg_data/ls.exe', 'pkg_data/md5sum.exe', 'pkg_data/mfc140u.dll', 'pkg_data/msys-2.0.dll', 'pkg_data/msys-iconv-2.dll', 'pkg_data/msys-intl-8.dll', 'pkg_data/msys-pcre-1.dll', 'pkg_data/py-spy.exe', 'pkg_data/res', 'pkg_data/restart.bat', 'pkg_data/syncthing.exe', 'pkg_data/tail.exe', 'pkg_data/ucrtbase.dll', 'pkg_data/un_install.bat', 'pkg_data/wget.exe', 'pkg_data/woolen.wang.cer', 'pkg_data/zcat.cmd', 'pkg_data/ztail.cmd'], 'excludes': ['Cython', 'PySide6', 'wx'], 'zip_include_packages': '*', 'zip_exclude_packages': ['woolen_quant', 'woolen_data_source', 'woolen_alpha', 'woolen_alpha_tool', 'woolen_config', 'woolen_sim_trade', 'py_help', 'bcolz', 'eventlet', 'python-socketio', 'Cryptodome', 'comtypes', 'apscheduler', 'pytz', 'certifi', 'lxml', 'scipy', 'passlib', 'flask_security', 'dask'], 'optimize': 1, 'include_msvcr': True}

To Reproduce Steps to reproduce the behavior (a setup.py or a minimal code sample will be good)

exe = Executable(script='woolen_quant_client.py',
                 base=base,
                 icon=os.path.join(PROJECT_ROOT, 'pc_icon_128.ico'),
                 )
setup(name='WoolenQuant',
              version='1.0',
              description='WoolenQuant',
              options={'build_exe': {'build_exe': 'build/woolen_quant_client', 'packages': ['pypinyin', 'itsdangerous', 'woolen_alpha_tool', 'flask_socketio', 'netifaces', 'woolen_quant', 'flask_inputs', 'setproctitle', 'pympler', 'marshmallow', 'idna.idnadata', 'flask_mail', 'socketio', 'watchdog', 'fastcache', 'dns', 'flask_compress', 'email_validator', 'simplejson', 'cython', 'woolen_alpha', 'logbook', 'woolen_data_source', 'markupsafe', 'lxml', 'engineio', 'pandas', 'numpy', 'eventlet', 'flask_security', 'certifi', 'cpuinfo', 'tkinter', 'py_help', 'prettytable', 'sentry_sdk', 'paramiko', 'flask', 'cached_property', 'flask_login', 'woolen_trade_broker', 'passlib', 'flask_wtf', 'flask_migrate', 'rpyc', 'apscheduler', 'pyzipper', 'flask_sqlalchemy', 'six', 'matplotlib', 'chardet', 'woolen_config', 'logging.config', 'sqlalchemy', 'pkg_resources', 'flask_script', 'pystray', 'better_exceptions', 'flask_cors', 'Cryptodome', 'pydantic', 'wrapt', 'flask_admin', 'psutil', 'flask_restful', 'flask_swagger_ui', 'cytoolz', 'talib', 'flask_babel', 'statsmodels', 'toolz', 'asyncio', 'jinja2', 'scipy', 'pysqlcipher3', 'seaborn', 'werkzeug', 'woolen_sim_trade'], 'include_files': ['web_ui/static.zip', 'config/', 'pkg_data/7z.exe', 'pkg_data/bash.exe', 'pkg_data/certmgr.exe', 'pkg_data/grep.exe', 'pkg_data/gzip.exe', 'pkg_data/install.bat', 'pkg_data/ls.exe', 'pkg_data/md5sum.exe', 'pkg_data/mfc140u.dll', 'pkg_data/msys-2.0.dll', 'pkg_data/msys-iconv-2.dll', 'pkg_data/msys-intl-8.dll', 'pkg_data/msys-pcre-1.dll', 'pkg_data/py-spy.exe', 'pkg_data/res', 'pkg_data/restart.bat', 'pkg_data/syncthing.exe', 'pkg_data/tail.exe', 'pkg_data/ucrtbase.dll', 'pkg_data/un_install.bat', 'pkg_data/wget.exe', 'pkg_data/woolen.wang.cer', 'pkg_data/zcat.cmd', 'pkg_data/ztail.cmd'], 'excludes': ['Cython', 'PySide6', 'wx'], 'zip_include_packages': '*', 'zip_exclude_packages': ['woolen_quant', 'woolen_data_source', 'woolen_alpha', 'woolen_alpha_tool', 'woolen_config', 'woolen_sim_trade', 'py_help', 'bcolz', 'eventlet', 'python-socketio', 'Cryptodome', 'comtypes', 'apscheduler', 'pytz', 'certifi', 'lxml', 'scipy', 'passlib', 'flask_security', 'dask'], 'optimize': 1, 'include_msvcr': True}, 'build_msi': bdist_msi_options},
              executables=[exe])

Expected behavior A clear and concise description of what you expected to happen. not raise exception Screenshots If applicable, add screenshots to help explain your problem.

  File "E:\git\python-3.11.6\Lib\site-packages\cx_Freeze\finder.py", line 260, in _import_module
    module = self._internal_import_module(name, deferred_imports)
             │                            │     └ [(<Module name='scipy.interpolate.fitpack', file=WindowsPath('E:/git/python-3.11.6/Lib/site-packages/scipy/interpolate/fitpack.p...
             │                            └ 'sympy.core._print_helpers'
             └ <cx_Freeze.finder.ModuleFinder object at 0x000001DB8B286ED0>
  File "E:\git\python-3.11.6\Lib\site-packages\cx_Freeze\finder.py", line 348, in _internal_import_module
    module = self._load_module(
  File "E:\git\python-3.11.6\Lib\site-packages\cx_Freeze\finder.py", line 415, in _load_module
    self._load_module_code(module, loader, deferred_imports)
    │                      │       │       └ [(<Module name='scipy.interpolate.fitpack', file=WindowsPath('E:/git/python-3.11.6/Lib/site-packages/scipy/interpolate/fitpack.p...
    │                      │       └ <_frozen_importlib_external.SourceFileLoader object at 0x000001DBA3251F90>
    │                      └ <Module name='sympy.core._print_helpers', file=WindowsPath('E:/git/python-3.11.6/Lib/site-packages/sympy/core/_print_helpers.py'...
    └ <cx_Freeze.finder.ModuleFinder object at 0x000001DB8B286ED0>
  File "E:\git\python-3.11.6\Lib\site-packages\cx_Freeze\finder.py", line 465, in _load_module_code
    self._scan_code(module.code, module, deferred_imports)
    │               │            │       └ [(<Module name='scipy.interpolate.fitpack', file=WindowsPath('E:/git/python-3.11.6/Lib/site-packages/scipy/interpolate/fitpack.p...
    │               │            └ <Module name='sympy.core._print_helpers', file=WindowsPath('E:/git/python-3.11.6/Lib/site-packages/sympy/core/_print_helpers.py'...
    │               └ <Module name='sympy.core._print_helpers', file=WindowsPath('E:/git/python-3.11.6/Lib/site-packages/sympy/core/_print_helpers.py'...
    └ <cx_Freeze.finder.ModuleFinder object at 0x000001DB8B286ED0>
  File "E:\git\python-3.11.6\Lib\site-packages\cx_Freeze\finder.py", line 661, in _scan_code
    self._scan_code(
  File "E:\git\python-3.11.6\Lib\site-packages\cx_Freeze\finder.py", line 661, in _scan_code
    self._scan_code(
  File "E:\git\python-3.11.6\Lib\site-packages\cx_Freeze\finder.py", line 626, in _scan_code
    imported_module = self._import_module(
  File "E:\git\python-3.11.6\Lib\site-packages\cx_Freeze\finder.py", line 260, in _import_module
    module = self._internal_import_module(name, deferred_imports)
             │                            │     └ [(<Module name='scipy.interpolate.fitpack', file=WindowsPath('E:/git/python-3.11.6/Lib/site-packages/scipy/interpolate/fitpack.p...
             │                            └ 'sympy.printing.latex'
             └ <cx_Freeze.finder.ModuleFinder object at 0x000001DB8B286ED0>
  File "E:\git\python-3.11.6\Lib\site-packages\cx_Freeze\finder.py", line 348, in _internal_import_module
    module = self._load_module(
  File "E:\git\python-3.11.6\Lib\site-packages\cx_Freeze\finder.py", line 410, in _load_module
    module = self._add_module(
  File "E:\git\python-3.11.6\Lib\site-packages\cx_Freeze\finder.py", line 95, in _add_module
    module = Module(name, path, filename, parent)
    │        │      │     │     │         └ <Module name='sympy.printing', file=WindowsPath('E:/git/python-3.11.6/Lib/site-packages/sympy/printing/__init__.py'), path=[Wind...
    │        │      │     │     └ WindowsPath('E:/git/python-3.11.6/Lib/site-packages/sympy/printing/latex.py')
    │        │      │     └ None
    │        │      └ 'sympy.printing.latex'
    │        └ <class 'cx_Freeze.module.Module'>
    └ None
  File "E:\git\python-3.11.6\Lib\site-packages\cx_Freeze\module.py", line 144, in __init__
    self.update_distribution(name)
    │                        └ 'sympy.printing.latex'
    └ <Module name='sympy.printing.latex', file=WindowsPath('E:/git/python-3.11.6/Lib/site-packages/sympy/printing/latex.py')>
  File "E:\git\python-3.11.6\Lib\site-packages\cx_Freeze\module.py", line 189, in update_distribution
    distribution = DistributionCache.from_name(name)
                   │                           └ 'sympy.printing.latex'
                   └ <class 'cx_Freeze.module.DistributionCache'>
  File "E:\git\python-3.11.6\Lib\site-packages\cx_Freeze\module.py", line 43, in from_name
    distribution = super().from_name(name)
                                     └ 'sympy.printing.latex'
  File "E:\git\python-3.11.6\Lib\importlib\metadata\__init__.py", line 563, in from_name
    return next(cls.discover(name=name))
                │                 └ 'sympy.printing.latex'
                └ <class 'cx_Freeze.module.DistributionCache'>
  File "E:\git\python-3.11.6\Lib\importlib\metadata\__init__.py", line 582, in <genexpr>
    resolver(context) for resolver in cls._discover_resolvers()
  File "<frozen importlib._bootstrap_external>", line 1547, in find_distributions
  File "E:\git\python-3.11.6\Lib\importlib\metadata\__init__.py", line 907, in find_distributions
    found = cls._search_paths(context.name, context.path)
            │                 │             └ <importlib.metadata.DistributionFinder.Context object at 0x000001DBA32522D0>
            │                 └ <importlib.metadata.DistributionFinder.Context object at 0x000001DBA32522D0>
            └ <class 'importlib.metadata.MetadataPathFinder'>
  File "E:\git\python-3.11.6\Lib\importlib\metadata\__init__.py", line 913, in _search_paths
    prepared = Prepared(name)
               │        └ 'sympy.printing.latex'
               └ <class 'importlib.metadata.Prepared'>
  File "E:\git\python-3.11.6\Lib\importlib\metadata\__init__.py", line 874, in __init__
    self.normalized = self.normalize(name)
    │                 │              └ 'sympy.printing.latex'
    │                 └ <importlib.metadata.Prepared object at 0x000001DBA2D5A990>
    └ <importlib.metadata.Prepared object at 0x000001DBA2D5A990>
  File "E:\git\python-3.11.6\Lib\importlib\metadata\__init__.py", line 882, in normalize
    return re.sub(r"[-_.]+", "-", name).lower().replace('-', '_')
           │                      └ 'sympy.printing.latex'
           └ <module 're' from 'E:\\git\\python-3.11.6\\Lib\\re\\__init__.py'>

RecursionError: maximum recursion depth exceeded

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

WoolenWang commented 4 months ago

like #1872 try to fix with pull #2272 works for me.