简体   繁体   English

在Python 3中使用“ tzwhere”模块

[英]Using “tzwhere” module in Python 3

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. 我正在尝试在Python 3中使用tzwhere模块。我想输入位置的坐标并返回时区。 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? 知道为什么会这样吗?

It looks like tzwhere works with Python 2 but not Python 3. I used the following code to convert coordinates to timezone: 看起来tzwhere适用于Python 2,但不适用于Python3。我使用以下代码将坐标转换为时区:

!pip install geopy
from geopy import geocoders
    g = geocoders.GoogleV3()
    tz = str(g.timezone((55.7825, 12.3686)))
    time = timezone(tz)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM