Psycopg3 fails to resolve 'timezone localtime' on MacOS - Mailing list pgsql-general

From Jerry Sievers
Subject Psycopg3 fails to resolve 'timezone localtime' on MacOS
Date
Msg-id 108B3AA1-8FBF-4C76-98BE-490156DAA5B5@comcast.net
Whole thread Raw
Responses Re: Psycopg3 fails to resolve 'timezone localtime' on MacOS
Re: Psycopg3 fails to resolve 'timezone localtime' on MacOS
Re: Psycopg3 fails to resolve 'timezone localtime' on MacOS
List pgsql-general
Has anyone run into This?

Psycopg3 fails to resolve timezone localtime on MacOS (Catalina).

It falls back to UTC regardless of whether running with/without the
tzdata package which I did try.

There is a /etc/localtime symlink on this box pointed at the correct
file in the tz data directory, which apparently doesn't get used.

Adding a temporary symlink directly into the tz data directory got
things working but I'm skeptical of such a hack.

Also tested w/PSYCOPG_IMPL=python.  Same results.

Psycopg2 had no issues.

Please advise.

Thx

----

tmp$ cat z
import psycopg, psycopg2, zoneinfo

for module in psycopg, psycopg2:
    try:
        print(module)
        conn = module.connect()
        cur = conn.cursor()
        cur.execute('select now()')
        cur.fetchone
    except Exception as e:
        print(e)
    print()

zoneinfo.ZoneInfo('localtime')

tmp$ python --version
Python 3.9.12

tmp$ python <z
<module 'psycopg' from '/usr/local/lib/python3.9/site-packages/psycopg/__init__.py'>
unknown PostgreSQL timezone: 'localtime'; will use UTC

<module 'psycopg2' from '/usr/local/lib/python3.9/site-packages/psycopg2/__init__.py'>
    # Ok here

From ZoneInfo...

Traceback (most recent call last):
  File
"/usr/local/Cellar/python@3.9/3.9.12/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
"/usr/local/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/resources.py",
line88, in open_binary 
    package = _get_package(package)
  File
"/usr/local/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/resources.py",
line49, in _get_package 
    module = _resolve(package)
  File
"/usr/local/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/resources.py",
line40, in _resolve 
    return import_module(name)
  File
"/usr/local/Cellar/python@3.9/3.9.12/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 17, in <module>
  File
"/usr/local/Cellar/python@3.9/3.9.12/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'
ERROR
tmp$ pip show psycopg psycopg_c
Name: psycopg
Version: 3.0.12
Summary: PostgreSQL database adapter for Python
Home-page: https://psycopg.org/psycopg3/
Author: Daniele Varrazzo
Author-email: daniele.varrazzo@gmail.com
License: GNU Lesser General Public License v3 (LGPLv3)
Location: /usr/local/lib/python3.9/site-packages
Requires:
Required-by:
---
Name: psycopg-c
Version: 3.0.12
Summary: PostgreSQL database adapter for Python -- C optimisation distribution
Home-page: https://psycopg.org/psycopg3/
Author: Daniele Varrazzo
Author-email: daniele.varrazzo@gmail.com
License: GNU Lesser General Public License v3 (LGPLv3)
Location: /usr/local/lib/python3.9/site-packages
Requires:
Required-by:
tmp$


pgsql-general by date:

Previous
From: Alexander Farber
Date:
Subject: Re: Displaying chat by punished users only to themselves (db fiddle attached)
Next
From: Tom Lane
Date:
Subject: Re: Psycopg3 fails to resolve 'timezone localtime' on MacOS