posit-dev / shinylive

Run Shiny on Python and R (compiled to wasm) in the browser
https://shinylive.io/py/examples/
MIT License
205 stars 16 forks source link

ZoneInfo('UTC') doesn't work #28

Closed stonebig closed 1 year ago

stonebig commented 1 year ago

ZoneInfo('UTC') doesn't function.

does this solution that is two weeks old may apply also for shiny-py ? https://github.com/jupyterlite/xeus-python-demo/issues/7#issuecomment-1375379923

>>> from zoneinfo import ZoneInfo
utc = ZoneInfo('UTC')
Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1004, 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 "<exec>", line 2, in <module>
  File "/lib/python3.10/zoneinfo/_zoneinfo.py", line 43, in __new__
    instance = cls._weak_cache.setdefault(key, cls._new_instance(key))
  File "/lib/python3.10/zoneinfo/_zoneinfo.py", line 70, in _new_instance
    file_obj = _common.load_tzdata(key)
  File "/lib/python3.10/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 UTC'

image

wch commented 1 year ago

In order to make this work, you can run:

import micropip
await micropip.install("tzdata")
import tzdata
from zoneinfo import ZoneInfo
utc = ZoneInfo('UTC')

For more information, see https://github.com/has2k1/mizani/issues/27