One Day Sec

When compiling an exchangelib-based Python script into an executable with PyInstaller, I get a 'No time zone found with key UTC' error. How can I fix this?

The error occurs because PyInstaller excludes the `tzdata` package that exchangelib needs for time zone handling. As mentioned in the guide, the solution is to compile with the `--collect-all tzdata` flag and `--onefile`: `pyinstaller --collect-all tzdata --onefile test.py`. This ensures all time zone data is bundled into the executable, allowing the script to process email timestamps correctly.
PyInstallertzdatatimezoneexecutable compilationexchangelib error

Browse all Q&A →