When running pyinstaller on a dateutil script it appears to lose date time info.
import dateutil
from dateutil import tz
def timezone_example(timezone_name):
return dateutil.tz.gettz(timezone_name)
if __name__ == "__main__":
silly_timezone_test = 'America/Los_Angeles'
print(timezone_example(silly_timezone_test))
input("here so that the installed exe doesn't auto shut down.")
Then 'installed' with:
py -m PyInstaller --onefile path/to/test.py --distpath resulting/path/folder
running the executable gives:
dateutil\zoneinfo\__init__.py:36: UserWarning: I/O error(2): No such file or directory
None
here so that the installed exe doesn't auto shut down.
"None" should be tzfile('America/Los_Angeles')" Which is the case when running the script directly in the terminal.
Note that I am using windows, Python 3.9.13 and PyInstaller 5.11.
I've already tried the solution mentioned in pyinstaller .exe cannot find 'dateutil.tz.__init__.tz' which using dateutil version 2.4.2 does not fix the issue for me.
Are there any other workarounds for this issue?
It appears that dateutil uses a file included in the package called dateutil-zoneinfo.tar.gz
during runtime to lookup timezone information. The issue is that pyinstaller isn't automatically including this file during compilation, so when your script runs, the dateutil code is unable to find the file, causing it to display a warning and return None
instead of the expected timezone information.
What you can do to fix this is to use the --collect-all
pyinstaller cli argument to indicate that pyinstaller should include all additional files in the dateutil package.
For example:
pyinstaller -F --collect-all dateutil path/to/test.py