hustcc / timeago

:hourglass: Simple library used to format datetime with `*** time ago` statement. eg: "3 hours ago".
http://timeago.org
MIT License
223 stars 37 forks source link

Locales not imported with PyInstaller #40

Open alexitx opened 2 years ago

alexitx commented 2 years ago

Example:

import time
import timeago

timestamp = time.time() - 30
print(timeago.format(timestamp))

PyInstaller command:

$ pyinstaller -F -c --noupx -i NONE main.py

Output:

Traceback (most recent call last):
  File "timeago\locales\__init__.py", line 25, in timeago_template
ModuleNotFoundError: No module named 'timeago.locales.en'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "main.py", line 7, in <module>
    print(timeago.format(timestamp))
  File "timeago\__init__.py", line 80, in format
  File "timeago\locales\__init__.py", line 29, in timeago_template
[28604] Failed to execute script 'main' due to unhandled exception!

Python 3.10.1 PyInstaller 4.8 timeago 1.0.15

The PyInstaller documentation provides examples of how to add hooks for hidden imports. There is also an example package repo.

A temporary workaround is to add each locale module manually using --hidden-import 'timeago.locales.<locale>'

I haven't worked with PyInstaller hooks, but it looks easy to implement. I can try to make a PR if needed when I look at it further.

debilin commented 10 months ago

+1