使用"tzwhere"Python 3中的模块 [英] Using "tzwhere" module in Python 3

查看:39
本文介绍了使用"tzwhere"Python 3中的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Python 3中的 tzwhere 模块.我想输入位置的坐标并返回时区.但是,当我运行以下代码时:

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

我收到此错误:

FileNotFoundError: [Errno 2] No such file or directory: '/Users/s.rayan/anaconda/lib/python3.6/site-packages/tzwhere/tz_world.json'

知道为什么会这样吗?

推荐答案

看起来tzwhere适用于Python 2,但不适用于Python3.我使用以下代码将坐标转换为时区:

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)

这篇关于使用"tzwhere"Python 3中的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆