exchangelib and pyinstaller - zoneinfo - tzdata - UTC issue

2.1k views Asked by At

In my python project, I'm using exchangelib and I needed to create an exe file. Using pyinstaller --onefile I had UTC errors (in general tzdata)- "No timzone in key UTC". Simplifying all and following this issue https://github.com/ecederstrand/exchangelib/issues/897 I noticed that the issue was the same with this simple code:

from zoneinfo import ZoneInfo
utc = ZoneInfo('UTC')

I also tried with py2exe, cx_freeze, forcing tzdata import, same issue.

I spent a lot of time finding a workaround and I want to share my temporary solution but also discuss other alternative solutions.

3

There are 3 answers

1
Umer On BEST ANSWER

This worked for me after exploring different options:

pyinstaller --collect-all tzdata --onefile file_name.py

PS: I have been facing this problem and reached here to explore about pyinstaller. Your solution works too but its a directory where as I wanted it to be exe.

0
Fabio Fracassi On

The workaround I found is to use pyinstaller --onedir (https://pyinstaller.readthedocs.io/en/stable/usage.html) and manually copy tzdata folder (\Python\Python39\Lib\site-packages\tzdata) in the main dir created by pyinstaller. Do you have more elegant other solutions?

2
Poer Hsueh On

I used the spec file for packaging, and packaged the resource files in the configuration.

binaries=[('C:\ProgramData\Anaconda3\Lib\site-packages\tzdata\zoneinfo\UTC','tzdata\zoneinfo')] pathex=['C:\ProgramData\Anaconda3\Lib\site-packages\tzdata\zoneinfo'] hiddenimports=['tzdata.zoneinfo']