使用;tzwhere";Python3中的模块
我正在尝试使用Python 3中的tzwhere模块。我想输入一个位置的坐标并返回时区。但是,当我运行以下代码时:使用;tzwhere";Python3中的模块,python,datetime,timezone,Python,Datetime,Timezone,我正在尝试使用Python 3中的tzwhere模块。我想输入一个位置的坐标并返回时区。但是,当我运行以下代码时: !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/
!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
我得到这个错误:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/s.rayan/anaconda/lib/python3.6/site-packages/tzwhere/tz_world.json'
知道为什么会发生这种情况吗?看起来tzwhere可以使用Python 2,但不能使用Python 3。我使用以下代码将坐标转换为时区:
!pip install geopy
from geopy import geocoders
g = geocoders.GoogleV3()
tz = str(g.timezone((55.7825, 12.3686)))
time = timezone(tz)
哪个操作系统?你检查过文件是否确实丢失了吗?你安装了什么版本的
tzwhere
吗?@MarkRansom I安装了tzwhere的3.0.1版。是的,tzwhere目录中缺少该文件。看起来这需要internet连接以及由此产生的查找开销。可能对某些人有好处,但对其他人没有好处。