{"id":420,"library":"tzlocal","title":"tzlocal: Local Time Zone Information for Python","description":"A Python module that provides the local time zone information as a tzinfo object. Current version: 5.3.1, released on March 5, 2025. Maintained under the MIT License. Requires Python 3.9 or higher. Release cadence: approximately every 6 months.","status":"active","version":"5.3.1","language":"python","source_language":"en","source_url":"https://github.com/regebro/tzlocal","tags":["time zone","local time","Python module","tzinfo"],"install":[{"cmd":"pip install tzlocal","lang":"bash","label":"Install tzlocal"}],"dependencies":[{"reason":"Required for time zone calculations","package":"pytz","optional":false}],"imports":[{"note":"Ensure correct import path to access the function","symbol":"get_localzone","correct":"from tzlocal import get_localzone"}],"quickstart":{"code":"from tzlocal import get_localzone\n\nlocal_timezone = get_localzone()\nprint(local_timezone)","lang":"python","description":"Retrieve and print the local time zone information."},"warnings":[{"fix":"Downgrade to version 4.0 for pytz compatibility.","message":"Version 5.0 removed pytz_deprecation_shim, returning only zoneinfo objects. For pytz compatibility, use version 4.0.","severity":"breaking","affected_versions":"5.0"},{"fix":"Use get_localzone() when time zone name is unavailable.","message":"get_localzone_name() may raise an error if no time zone name is configured on Unix systems. Use get_localzone() if only the tzinfo object is needed.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-05-12T13:42:07.438Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"Install the package using pip: `pip install tzlocal`","cause":"The 'tzlocal' package is not installed in the current Python environment.","error":"ModuleNotFoundError: No module named 'tzlocal'"},{"fix":"Upgrade your Python interpreter to version 3.9 or higher, or use an older `tzlocal` version compatible with your Python (though this is not recommended).","cause":"Attempting to install or use `tzlocal` version 5.3.1 (which requires Python 3.9 or higher) with an older Python interpreter.","error":"ERROR: Package 'tzlocal' requires a different Python version: X.Y.Z. Expected '>=3.9'"},{"fix":"Use `datetime.datetime.replace()` or `datetime.datetime.astimezone()` to make a naive datetime object timezone-aware:\n```python\nimport datetime\nfrom tzlocal import get_localzone\n\nlocal_tz = get_localzone()\nnaive_dt = datetime.datetime.now() # naive datetime\naware_dt = naive_dt.replace(tzinfo=local_tz)\n# Or, to convert an already aware datetime from one zone to another:\n# dt_utc = datetime.datetime.now(datetime.timezone.utc)\n# aware_dt_local = dt_utc.astimezone(local_tz)\n```","cause":"This error occurs when trying to use the `localize` method (common with `pytz` timezone objects) on a `zoneinfo.ZoneInfo` object, which is returned by `tzlocal.get_localzone()` from version 4.0 onwards. `zoneinfo` objects do not have a `localize` method.","error":"AttributeError: 'ZoneInfo' object has no attribute 'localize'"},{"fix":"Import the function directly from the `tzlocal` module:\n```python\nfrom tzlocal import get_localzone\n```","cause":"The `get_localzone` function is directly available under the `tzlocal` module, not as a submodule.","error":"ModuleNotFoundError: No module named 'tzlocal.get_localzone'"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":1.6,"disk_size":"17.9M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":1.6,"disk_size":"18M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.07,"mem_mb":1.9,"disk_size":"19.7M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.06,"mem_mb":1.9,"disk_size":"20M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.05,"mem_mb":1.9,"disk_size":"11.6M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.05,"mem_mb":1.9,"disk_size":"12M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.06,"mem_mb":1.9,"disk_size":"11.2M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.05,"mem_mb":1.7,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1.6,"disk_size":"17.4M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1.6,"disk_size":"18M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}