scverse / anndata

Annotated data.
http://anndata.readthedocs.io
BSD 3-Clause "New" or "Revised" License
571 stars 152 forks source link

`KeyError` on Flask app using `pyinstaller` with `setuptools_scm` #1578

Closed matt-sd-watson closed 1 month ago

matt-sd-watson commented 1 month ago

Please make sure these conditions are met

Report

I am attempting to bundle a Python package containing numerous modules supporting a Flask application into an executable using pyinstaller. The pkg is generated using the following spec:

# -*- mode: python ; coding: utf-8 -*-
import sys ; sys.setrecursionlimit(sys.getrecursionlimit() * 5)

a = Analysis(
    ['my_app/wsgi.py'],
    pathex=[],
    binaries=[],
    datas=[(my_app', my_app'), ('my_app/templates', 'templates'), ('my_app/assets', 'assets'),
    ('/home/matt/anaconda3/lib/python3.9/site-packages/jupyter_dash', 'jupyter_dash'),
('/home/matt/anaconda3/lib/python3.9/site-packages/dash_canvas', 'dash_canvas'),
('/home/matt/anaconda3/lib/python3.9/site-packages/dash_ag_grid', 'dash_ag_grid'),
('/home/matt/anaconda3/lib/python3.9/site-packages/dash_draggable', 'dash_draggable'),
('/home/matt/anaconda3/lib/python3.9/site-packages/dash_testing_stub', 'dash_testing_stub'),
('/home/matt/anaconda3/lib/python3.9/site-packages/setuptools.pth', 'setuptools.pth'),
('/home/matt/anaconda3/lib/python3.9/site-packages/setuptools_scm', 'setuptools_scm'),
('/home/matt/anaconda3/lib/python3.9/site-packages/dash_tour_component', 'dash_tour_component'),
('/home/matt/anaconda3/lib/python3.9/site-packages/anndata', 'anndata'),
('/home/matt/anaconda3/lib/python3.9/site-packages/dash_bootstrap_components', 'dash_bootstrap_components'),
('/home/matt/anaconda3/lib/python3.9/site-packages/dash_google_auth', 'dash_google_auth'),
('/home/matt/anaconda3/lib/python3.9/site-packages/dash', 'dash'),
('/home/matt/anaconda3/lib/python3.9/site-packages/dash_extensions', 'dash_extensions'),
('/home/matt/anaconda3/lib/python3.9/site-packages/dash_table', 'dash_table'),
('/home/matt/anaconda3/lib/python3.9/site-packages/setuptools', 'setuptools'),
('/home/matt/anaconda3/lib/python3.9/site-packages/dash_auth', 'dash_auth'),
('/home/matt/anaconda3/lib/python3.9/site-packages/dash_uploader', 'dash_uploader'),
('/home/matt/anaconda3/lib/python3.9/site-packages/dash_bootstrap_templates', 'dash_bootstrap_templates'),
('/home/matt/anaconda3/lib/python3.9/site-packages/dash_html_components', 'dash_html_components'),
('/home/matt/anaconda3/lib/python3.9/site-packages/dash_bio', 'dash_bio'),
('/home/matt/anaconda3/lib/python3.9/site-packages/dash_mantine_components', 'dash_mantine_components'),
('/home/matt/anaconda3/lib/python3.9/site-packages/dash_daq', 'dash_daq'),
('/home/matt/anaconda3/lib/python3.9/site-packages/dash_core_components', 'dash_core_components')
],
    hiddenimports=[],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=['tkinter'],
    noarchive=False,
    optimize=0,
)
pyz = PYZ(a.pure)

exe = EXE(
    pyz,
    a.scripts,
    a.binaries,
    a.datas,
    [],
    name='my_app',
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    upx_exclude=[],
    runtime_tmpdir=None,
    console=False,
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
)

However, upon trying to execute the executable, I get the following trace:

Traceback (most recent call last):
  File "anndata/_metadata.py", line 28, in <module>
  File "/tmp/_MEIlzkku8/setuptools_scm/_get_version_impl.py", line 155, in get_version
    maybe_version = _get_version(config, force_write_version_files=True)
  File "/tmp/_MEIlzkku8/setuptools_scm/_get_version_impl.py", line 93, in _get_version
    parsed_version = parse_version(config)
  File "/tmp/_MEIlzkku8/setuptools_scm/_get_version_impl.py", line 56, in parse_version
    or parse_scm_version(config)
  File "/tmp/_MEIlzkku8/setuptools_scm/_get_version_impl.py", line 35, in parse_scm_version
    return _entrypoints.version_from_entrypoint(
  File "/tmp/_MEIlzkku8/setuptools_scm/_entrypoints.py", line 53, in version_from_entrypoint
    for ep in iter_matching_entrypoints(root, entrypoint, config):
  File "/tmp/_MEIlzkku8/setuptools_scm/discover.py", line 63, in iter_matching_entrypoints
    for ep in iter_entry_points(entrypoint):
  File "/tmp/_MEIlzkku8/setuptools_scm/_entrypoints.py", line 63, in iter_entry_points
    eps: EntryPoints = entry_points(group=group)
  File "/tmp/_MEIlzkku8/setuptools_scm/_entrypoints.py", line 38, in entry_points
    return EntryPoints(legacy_entry_points()[group])
KeyError: 'setuptools_scm.parse_scm'

It appears that the version parsing here could be causing this issue.

Versions

-----
anndata             0.10.8
session_info        1.0.0
-----
backports           NA
cython_runtime      NA
dateutil            2.8.2
exceptiongroup      1.1.1
h5py                3.8.0
importlib_metadata  NA
jaraco              NA
more_itertools      9.1.0
mpl_toolkits        NA
natsort             8.3.1
numexpr             2.8.7
numpy               1.24.3
ordered_set         4.1.0
packaging           24.1
pandas              2.0.2
pytz                2023.3
scipy               1.10.1
setuptools          72.1.0
setuptools_scm      NA
six                 1.16.0
tomli               2.0.1
zipp                NA
zoneinfo            NA
flying-sheep commented 1 month ago

Hi, the versions you specify don’t match the version that was installed when that error occurred.

As you can see, _metadata.py doesn’t exist in 0.10.8: https://github.com/scverse/anndata/tree/0.10.8/src/anndata The last version that still had that file was 0.9.2.

In any case, there’s no reason why setuptools_scm should be installed in a runtime environment. Just make sure it doesn’t end up in there and you’re fine. I’m going to close this issue because of this reason.

Finally, have you tried PyApp? It’s a modern take on PyInstaller’s job: https://ofek.dev/pyapp/latest/