Using “tzwhere” module in Python 3

微笑、不失礼 提交于 2021-02-08 06:51:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!