0

I tried to make an exe file using the code I wrote using Kivy/KivyMD. I'm able to successfully generate the exe file. But the app crashes and an error is thrown after I click one of the list items:

 Traceback (most recent call last):
   File "scanpy\_metadata.py", line 28, in <module>
   File "pathlib.py", line 1221, in read_text
   File "pathlib.py", line 1208, in open
   File "pathlib.py", line 1063, in _opener
 FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\xie186\\AppData\\Local\\Temp\\_MEI82402\\pyproject.toml'

 During handling of the above exception, another exception occurred:

 Traceback (most recent call last):
   File "main.py", line 178, in <module>
   File "kivy\app.py", line 950, in run
   File "kivy\base.py", line 582, in runTouchApp
   File "kivy\base.py", line 347, in mainloop
   File "kivy\base.py", line 391, in idle
   File "kivy\base.py", line 342, in dispatch_input
   File "kivy\base.py", line 308, in post_dispatch_input
   File "kivy\_event.pyx", line 709, in kivy._event.EventDispatcher.dispatch
   File "kivymd\uix\list.py", line 854, in on_touch_up
   File "kivymd\uix\behaviors\ripple_behavior.py", line 296, in on_touch_up
   File "kivy\uix\behaviors\button.py", line 179, in on_touch_up
   File "kivy\_event.pyx", line 709, in kivy._event.EventDispatcher.dispatch
   File "main.py", line 118, in <lambda>
   File "main.py", line 139, in set_example_screen
   File "<string>", line 1, in <module>
   File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
   File "libs\baseclass\tabs.py", line 6, in <module>
   File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
   File "scanpy\__init__.py", line 3, in <module>
     =======
   File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
   File "scanpy\_metadata.py", line 38, in <module>
   File "scanpy\_compat.py", line 25, in pkg_metadata
   File "importlib_metadata\__init__.py", line 984, in metadata
   File "importlib_metadata\__init__.py", line 561, in from_name
 importlib_metadata.PackageNotFoundError: No package metadata was found for scanpy
[10680] Failed to execute script 'main' due to unhandled exception!

To reproduce the error, please use the code here:

git clone https://github.com/xie186/pitaya.git
cd pitaya/
git checkout 067abaf4ead73862b2baa27909f6079f75fb2feb
pip install -r requirements.txt
python -m PyInstaller  .\pyinstaller.spec
cd dist/
.\pitaya.exe
# Then click one of the list items. 

Based on the error, it's because of the code here: https://github.com/theislab/scanpy/blob/16e62d1336a95966238113cdb5ab50f7d9f880ce/scanpy/_metadata.py#L28

Scany is a package my app is dependent on. It tries to read the file here: https://github.com/theislab/scanpy/blob/master/pyproject.toml But the file is not available when I run the exe file.

If I run the app in venv environment, it runs fine. Any help will be appreciated!

xie186
  • 487
  • 4
  • 9

1 Answers1

0

Workaround: As this is most probably a packaging artifact, i would suggest bypassing it by changing the "scanpy\_metadata.py" file. Specifically, after the exception statement write

except (ImportError, LookupError, FileNotFoundError):
    __version__ = '0.0.0'  # or the real version number
    __author__ = 'Theis lab'
    __email__ = 'f.alex.wolf@gmx.de, philipp.angerer@helmholtz-muenchen.de'

This way your code wouldn't try (and fail) to find the "pyproject.toml" file, and will not ask importlib_metadata to locate the package metadata for scanpy (and also fail)