问题
I am trying to use the tzwhere module in Python 3. I want to enter in the coordinates of a location and return the timezone. However, when I run the following code:
!pip install pytz
!pip install tzwhere
import pytz
from tzwhere import tzwhere
tzwhere = tzwhere.tzwhere()
timezone_str = tzwhere.tzNameAt(37.3880961, -5.9823299)
print(timezone_str) #Europe/Madrid
I get this error:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/s.rayan/anaconda/lib/python3.6/site-packages/tzwhere/tz_world.json'
Any idea why this is happening?
回答1:
It looks like tzwhere works with Python 2 but not Python 3. I used the following code to convert coordinates to timezone:
!pip install geopy
from geopy import geocoders
g = geocoders.GoogleV3()
tz = str(g.timezone((55.7825, 12.3686)))
time = timezone(tz)
来源:https://stackoverflow.com/questions/45019641/using-tzwhere-module-in-python-3