metergroup / GRANOLA

Apache License 2.0
5 stars 1 forks source link

Ensure compatibility with pyinstaller #36

Open prosaicpudding opened 2 years ago

prosaicpudding commented 2 years ago

šŸš€ Feature Request

Ensure that this package is compatible with pyinstaller.

šŸ”ˆ Motivation

I have observed that importing this package into a project that is packaged into an executable with pyinstaller will break the resulting executable. Specifically, you see the following, even if pyserial is installed, and in fact is used elsewhere in the same program without issue:

2022-05-18 11:20:44-0700 [-]  Traceback (most recent call last):
2022-05-18 11:20:44-0700 [-]    File "calibration\reef.py", line 97, in <module>
2022-05-18 11:20:44-0700 [-]    File "c:\users\helen.catanese\pycharmprojects\skalahub\venv\Lib\site-packages\PyInstaller/loader/pyimod03_importers.py", line 391, in load_module
2022-05-18 11:20:44-0700 [-]      exec(bytecode, module.__dict__)
2022-05-18 11:20:44-0700 [-]    File "calibration\sockeye_comm.py", line 7, in <module>
2022-05-18 11:20:44-0700 [-]    File "c:\users\helen.catanese\pycharmprojects\skalahub\venv\Lib\site-packages\PyInstaller/loader/pyimod03_importers.py", line 391, in load_module
2022-05-18 11:20:44-0700 [-]      exec(bytecode, module.__dict__)
2022-05-18 11:20:44-0700 [-]    File "site-packages\granola\__init__.py", line 2, in <module>
2022-05-18 11:20:44-0700 [-]      Modules
2022-05-18 11:20:44-0700 [-]    File "c:\users\helen.catanese\pycharmprojects\skalahub\venv\Lib\site-packages\PyInstaller/loader/pyimod03_importers.py", line 391, in load_module
2022-05-18 11:20:44-0700 [-]      exec(bytecode, module.__dict__)
2022-05-18 11:20:44-0700 [-]    File "site-packages\granola\breakfast_cereal.py", line 38, in <module>
2022-05-18 11:20:44-0700 [-]    File "site-packages\granola\breakfast_cereal.py", line 327, in Cereal
2022-05-18 11:20:44-0700 [-]    File "site-packages\granola\utils.py", line 121, in check_min_package_version
2022-05-18 11:20:44-0700 [-]    File "site-packages\pkg_resources\__init__.py", line 481, in get_distribution
2022-05-18 11:20:44-0700 [-]      
2022-05-18 11:20:44-0700 [-]    File "site-packages\pkg_resources\__init__.py", line 357, in get_provider
2022-05-18 11:20:44-0700 [-]      
2022-05-18 11:20:44-0700 [-]    File "site-packages\pkg_resources\__init__.py", line 900, in require
2022-05-18 11:20:44-0700 [-]      
2022-05-18 11:20:44-0700 [-]    File "site-packages\pkg_resources\__init__.py", line 786, in resolve
2022-05-18 11:20:44-0700 [-]      
2022-05-18 11:20:44-0700 [-]  pkg_resources.DistributionNotFound: The 'pyserial' distribution was not found and is required by the application

I suspect this issue is related to how/where/when pyinstaller packages up dependencies. But I would like to build a minimum viable example to ensure that it isn't some idiosyncrasy of my project.

šŸ›° Alternatives

Rather than any code changes, we might also provide documentation on a known workaround.

šŸ“Ž Additional context

prosaicpudding commented 2 years ago

I think this is in fact a limitation of pyinstaller. https://github.com/pyinstaller/pyinstaller/issues/4795 Checking to see if the copy_metadata hook can be used to resolve the issue.

82phil commented 2 years ago

Hmm I got it working for Python 3 using pyinstaller hooks with your package (pyinstaller-hook-metadata) but I don't think it's going to work for Python 2. The latest PyInstaller that supported it was 3.6, and so far, I haven't figured out if there is a way to provide pyinstaller 3.6 the hooks.

I will see if I can use a different path to get the version of 'pyserial', which will simplify to from serial import __version__, as I think it is still available when pyinstaller freezes the application.