FIXED: Unable to use Python zoneinfo for time zone [2023.12120 Win 11]

It looks like something about the python library included with TD doesn’t support the zoneinfo module to get time zones by name.

If you attempt something like this:

import zoneinfo
print(zoneinfo.ZoneInfo('America/New_York'))

It produces the error below. It seems like something about how module imports are handled isn’t able to find the underlying data that zoneinfo depends on.

This is in 2023.12120 on Windows 11.

Traceback (most recent call last):
  File "C:\Program Files\Derivative\TouchDesigner.2023.12120\bin\Lib\zoneinfo\_common.py", line 12, in load_tzdata
    return resources.files(package_name).joinpath(resource_name).open("rb")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Derivative\TouchDesigner.2023.12120\bin\Lib\importlib\resources\_common.py", line 22, in files
    return from_package(get_package(package))
                        ^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Derivative\TouchDesigner.2023.12120\bin\Lib\importlib\resources\_common.py", line 53, in get_package
    resolved = resolve(package)
               ^^^^^^^^^^^^^^^^
  File "C:\Program Files\Derivative\TouchDesigner.2023.12120\bin\Lib\importlib\resources\_common.py", line 44, in resolve
    return cand if isinstance(cand, types.ModuleType) else importlib.import_module(cand)
                                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Derivative\TouchDesigner.2023.12120\bin\Lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1128, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1128, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1142, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'tzdata'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<Textport>", line 1
  File "C:\Program Files\Derivative\TouchDesigner.2023.12120\bin\Lib\zoneinfo\_common.py", line 24, in load_tzdata
    raise ZoneInfoNotFoundError(f"No time zone found with key {key}")
zoneinfo._common.ZoneInfoNotFoundError: 'No time zone found with key America/Los_Angeles'

What’s interesting in the Python doc:

By default, zoneinfo uses the system’s time zone data if available; if no system time zone data is available, the library will fall back to using the first-party tzdata package available on PyPI.

So I think it’s indeed failing because it fell back on tzdata. But we are not shipping tzdata.

Now to test that it’s working with what they call the system time zone data, I don’t quite have a clue.

Do you have whatever is needed setup on your end and it’s still failing ? Or you did not notice that before reporting the bug?

Thanks,
Michel

This appears to be the same problem:

So maybe this is a larger windows python issue.
There might be a way to set it up, but I haven’t found it. Also having to do that on every machine that runs projects depending on that seems like it shouldn’t be necessary.

Maybe it’s better to use TD PIP to auto download the tzdata package locally than trying to rely on something system-wide.

Well since it’s a builtin library being affected, tzdata should probably ship as a dep to that builtin lib, with TouchDesigner. But that’s a weird thing to do from the python folks…

I’ll check with devs.

1 Like

Ya even the default Python 3.11 installation fails when trying to use zoneinfo. Strange it would ship without a subdependency.
I’ve included ‘tzdata’ in future builds coming out in the 2025 release

1 Like

awesome thanks!