Timezone Information Missing in pytz?

pytz timezones
pytz python example
pytz get local timezone
pytz localize
pytz utcoffset
tzinfo=pytz
pytz normalize
django timezone

I'm having a very weird problem with Python's pytz: it seems to have an incomplete catalog of timezones on my system (MacOS X 10.8.5, system Python 2.7.5).

>>> from pytz import timezone
>>> import pytz

>>> utc = pytz.utc
>>> utc.zone
'UTC'

>>> eastern = timezone('US/Eastern')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pytz/__init__.pyc", line 182, in timezone

pytz.exceptions.UnknownTimeZoneError: 'US/Eastern'

So the timezone 'US/Eastern' can't be found. Accordingly I tried to have a look at the catalog of timezones that pytz offers:

>>> from pytz import all_timezones
>>> for tz in pytz.all_timezones:
...     print tz
... 
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Asmera
Africa/Bamako
Africa/Bangui
Africa/Banjul
Africa/Bissau
Africa/Blantyre
Africa/Brazzaville
Africa/Bujumbura
Africa/Cairo
Africa/Casablanca
Africa/Ceuta
Africa/Conakry
Africa/Dakar
Africa/Dar_es_Salaam
Africa/Djibouti
Africa/Douala
Africa/El_Aaiun
Africa/Freetown
Africa/Gaborone
Africa/Harare
Africa/Johannesburg
Africa/Juba
Africa/Kampala
Africa/Khartoum
Africa/Kigali
Africa/Kinshasa
Africa/Lagos
Africa/Libreville
Africa/Lome
Africa/Luanda
Africa/Lubumbashi
Africa/Lusaka
Africa/Malabo
Africa/Maputo
Africa/Maseru
Africa/Mbabane
Africa/Mogadishu
Africa/Monrovia
Africa/Nairobi
Africa/Ndjamena
Africa/Niamey
Africa/Nouakchott
Africa/Ouagadougou
Africa/Porto-Novo
Africa/Sao_Tome
Africa/Timbuktu
Africa/Tripoli
Africa/Tunis
Africa/Windhoek
America/Adak
America/Anchorage
America/Anguilla
America/Antigua
America/Araguaina
America/Argentina/Buenos_Aires
America/Argentina/Catamarca
America/Argentina/ComodRivadavia
America/Argentina/Cordoba
America/Argentina/Jujuy
America/Argentina/La_Rioja
America/Argentina/Mendoza
America/Argentina/Rio_Gallegos
America/Argentina/Salta
America/Argentina/San_Juan
America/Argentina/San_Luis
America/Argentina/Tucuman
America/Argentina/Ushuaia
America/Aruba
America/Asuncion
America/Atikokan
America/Atka
America/Bahia
America/Bahia_Banderas
America/Barbados
America/Belem
America/Belize
America/Blanc-Sablon
America/Boa_Vista
America/Bogota
America/Boise
America/Buenos_Aires
America/Cambridge_Bay
America/Campo_Grande
America/Cancun
America/Caracas
America/Catamarca
America/Cayenne
America/Cayman
America/Chicago
America/Chihuahua
America/Coral_Harbour
America/Cordoba
America/Costa_Rica
America/Creston
America/Cuiaba
America/Curacao
America/Danmarkshavn
America/Dawson
America/Dawson_Creek
America/Denver
America/Detroit
America/Dominica
America/Edmonton
America/Eirunepe
America/El_Salvador
America/Ensenada
America/Fort_Wayne
America/Fortaleza
America/Glace_Bay
America/Godthab
America/Goose_Bay
America/Grand_Turk
America/Grenada
America/Guadeloupe
America/Guatemala
America/Guayaquil
America/Guyana
America/Halifax
America/Havana
America/Hermosillo
America/Indiana/Indianapolis
America/Indiana/Knox
America/Indiana/Marengo
America/Indiana/Petersburg
America/Indiana/Tell_City
America/Indiana/Vevay
America/Indiana/Vincennes
America/Indiana/Winamac
America/Indianapolis
America/Inuvik
America/Iqaluit
America/Jamaica
America/Jujuy
America/Juneau
America/Kentucky/Louisville
America/Kentucky/Monticello
America/Knox_IN
America/Kralendijk
America/La_Paz
America/Lima
America/Los_Angeles

So as you can see, it ends rather prematurely and many many timezones are missing. I tried to overcome this by updating the Olson database pytz uses internally:

$ sudo pip install -U pytz

But the problem persists...

Any ideas what might be going wrong here? Am I missing something?


I cannot say why your installation of pytz is broken, but here's a possible fix:

  1. Download the .zip archive of pytz from the Python Package Index.
  2. In Terminal.app, run pip show pytz.
  3. Using the path it returns, run open /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (replacing my path with yours if different). This will launch a Finder window with your Python modules.
  4. Find the pytz/ folder. Open it.
  5. Replace the zoneinfo/ folder with the zoneinfo/ folder that's in the .zip archive you downloaded in step 1 from PyPI.

python - Timezone Information Missing in pytz?, I cannot say why your installation of pytz is broken, but here's a possible fix: Download the .zip archive of pytz from the Python Package Index. In Terminal.​app  Internally, this is a class that uses time.timezone and time.altzone (switching based on time.daylight), but creates a suitable timezone object from that. You use this instead of a pytz timezone. The alternative is to read the currently configured timezone from the operating system instead, but this differs widely from OS to OS.


I had a similar exception UnknownTimeZoneError: Can not find any timezone configuration when i tried to run my app inside a docker container with the latest ubuntu images. It turned out that tzdata was missing. Installing tzdata package fixed it:

apt-get install -y tzdata

# Maybe you will need to reconfigure the timezone as well:
ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime
dpkg-reconfigure -f noninteractive tzdata

(Use sudo if you have to)

pytz · PyPI, The first is to use the localize() method provided by the pytz library. This is used to localize a naive datetime (datetime with no timezone information): >>> loc_dt  The first is to use the localize() method provided by the pytz library. This is used to localize a naive datetime (datetime with no timezone information): >>> loc_dt = eastern.localize(datetime(2002, 10, 27, 6, 0, 0)) >>> print(loc_dt.strftime(fmt)) 2002-10-27 06:00:00 EST-0500


Understand that the time zone data in pytz comes from the IANA time zone database, also known as the Olson database, or simply the tz database.

In this data, certain identifiers (such as US/Eastern) are simply pointers (aka "links" or "aliases") to the real time zone. Links are there for several different reasons, usually for backwards compatibility purposes. In this case, the US/Eastern time zone is a link to America/New_York, which is the true time zone that you should be using. (I believe this particular switch happened in 1993).

You can see other time zones that are just there for backwards compatibility here. See also this chart on Wikipedia which lists the time zones, and clearly indicates which zones are links and where those links point to.

As to why pytz isn't accepting backward compatible zones on your system, I'm not exactly certain. It certainly should, and even shows these in their documentation. You might try re-installing it as Jacob suggested. But even then, you should prefer America/New_York instead of US/Eastern.

No timezone configuration in running image · Issue #610 , When I run a python command that needs timezone information I get an error pointing to a missing timezone configuration. in _get_localzone(_root) 115 return pytz.tzfile.build_tzinfo('local', tzfile) 116 --> 117 raise pytz. pytz. Brings the IANA tz database into Python. This library allows accurate and cross platform timezone calculations. pytz contains generated code, and this branch generates it. The actual pytz code and documentation can be found in the src/ directory. Usage Information / Documentation. See the pytz README. pytz for Enterprise


Tried reinstall, but bug not gone.

Then, I open pytz/__init__.py, add a line zone = 'UTC', problem is gone:

zone = _unmunge_zone(zone)
zone = 'UTC'
if zone not in _tzinfo_cache:
    if zone in all_timezones_set:
        fp = open_resource(zone)
        try:
            _tzinfo_cache[zone] = build_tzinfo(zone, fp)
        finally:
            fp.close()
    else:
        raise UnknownTimeZoneError(zone)

This is quick and simple solution, but you'd better find the real problem( version? system? ) if you have time.

pytz, pytz brings the Olson timezone database into Python. This library #1720794 Test for sortedness of all_timezones and common_timezones is missing. pytz 6. The following are code examples for showing how to use pytz.country_timezones().They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.


All solutions didn't work for me in a Spark cluster. But I found the "pendulum" library and it works just fine.

import pendulum
timezone = pendulum.timezone('Europe/Saratov')

Bug #572530 “pytz missing some timezone names that are present i , For example, pytz doesn't know how to look up 'BRT': >>> pytz.timezone('BRT') Traceback (most recent call last): File " ", line 1, in File  If you think a timezone definition is incorrect, I probably can’t fix it. pytz is a direct translation of the Olson timezone database, and changes to the timezone definitions need to be made to this source. If you find errors they should be reported to the time zone mailing list, linked from http://www.iana.org/time-zones.


7.1. datetime — Basic date and time types, An abstract base class for time zone information objects. object timedelta tzinfo timezone time date datetime For a complete and up-to-date set of DST rules # and timezone definitions, visit the Olson Database (or try pytz): method must consider times in the “missing hour” (2:MM for Eastern) to be in daylight time. If you think a timezone definition is incorrect, I probably can’t fix it. pytz is a direct translation of the Olson timezone database, and changes to the timezone definitions need to be made to this source. If you find errors they should be reported to the time zone mailing list, linked from http://www.iana.org/time-zones.


PEP 615 -- Support for the IANA Time Zone Database in the , System time zone information; The tzdata Python package Using a pytz-like interface; Windows support via Microsoft's ICU API; Alternative Although this information is missing in the compiled TZif binaries, it is present in  Always use aware datetime object, i.e. with timezone information. That makes sure you can compare them directly (aware and unaware datetime objects are not comparable) and will return them correctly to users. Leverage pytz to have timezone objects. Use ISO 8601 as input and output string format.


pandas.Series.dt.tz_convert, tz : string, pytz.timezone, dateutil.tz.tzfile or None. Time zone for time. A tz of None will convert to UTC and remove the timezone information. Returns:. When support for time zones is enabled, Django stores datetime information in UTC in the database, uses time-zone-aware datetime objects internally, and translates them to the end user’s time zone in templates and forms. This is handy if your users live in more than one time zone and you want to display datetime information according to each