[mythtv] MacOS python3.9+ IANA Time Zone Support

John Hoyt john.hoyt at gmail.com
Fri Dec 3 10:56:27 UTC 2021


On Wed, Dec 1, 2021 at 3:25 PM Roland Ernst <rcrernst at gmail.com> wrote:

> Hi,
> I kindly ask about the status of macoOs python 3.9+ and the support for
> IANA time zones:
> see https://docs.python.org/3/library/zoneinfo.html
>
> My question is about recognizing the local time zone if given as
> 'localtime' parameter.
> What does the following sequence show:
>
> $ python3
> >>> from zoneinfo import ZoneInfo
> >>> from datetime import datetime
> >>> localtz = ZoneInfo('localtime')
> >>> now = datetime.now(localtz)
> >>> now.tzname()
> 'CET'
> >>> now.tzinfo
> zoneinfo.ZoneInfo(key='localtime')
>
> This should report the name of the the current time zone (in my case
> 'CET') and the current
> usage of  pythons 'tzinfo' parameter.
>
> My plan is to update the Mythtv's python bindings in that direction.
>

macOS by default installs older versions of python (on Monterey it installs
3.8).

To get python39 support, you'll need to install from somewhere else (e.g.
macports, homebrew).

When I do my builds, I use macports for a number of reasons that I won't go
into on this thread and I have recently upgraded the build process locally
to move to python3.9.

I just tried running the functions you suggest on my system with macports
python39 and had to add received the following error:

>>> localtz = ZoneInfo('localtime')

Traceback (most recent call last):

  File
"/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/zoneinfo/_common.py",
line 12, in load_tzdata

    return importlib.resources.open_binary(package_name, resource_name)

  File
"/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/resources.py",
line 88, in open_binary

    package = _get_package(package)

  File
"/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/resources.py",
line 49, in _get_package

    module = _resolve(package)

  File
"/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/resources.py",
line 40, in _resolve

    return import_module(name)

  File
"/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py",
line 127, in import_module

    return _bootstrap._gcd_import(name[level:], package, level)

  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import

  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load

  File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked

  File "<frozen importlib._bootstrap>", line 228, in
_call_with_frames_removed

  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import

  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load

  File "<frozen importlib._bootstrap>", line 984, 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 "<stdin>", line 1, in <module>

  File
"/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/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
localtime'

Can you point me to the missing python module(s)?  I have installed tzdata
as it seemed like it would have been the correct solution to no avail.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mythtv.org/pipermail/mythtv-dev/attachments/20211203/77877a0c/attachment.htm>


More information about the mythtv-dev mailing list