Python箭头包时区错误?

时间:2014-12-17 18:44:01

标签: python python-2.7 registry windows-7-x64 python-dateutil

我在Windows 7的python 2.7中运行以下代码,但收到错误:

import arrow

timeNow = arrow.utcnow()
print timeNow
timePST = timeNow.to('US/Pacific')
timeMST = timeNow.to('US/Mountain')

ERROR:

Traceback (most recent call last):
  File "C:\Users\flann\Dropbox\Personal\GoogleTrendsFutures\pythonCode\testBug.py", line 5, in <module>
    timePST = timeNow.to('US/Pacific')
  File "C:\Python27\lib\site-packages\arrow\arrow.py", line 456, in to
    tz = parser.TzinfoParser.parse(tz)
  File "C:\Python27\lib\site-packages\arrow\parser.py", line 295, in parse
    tzinfo = tz.gettz(string)
  File "C:\Python27\lib\site-packages\dateutil\tz.py", line 963, in gettz
    tz = tzwin(name)
  File "C:\Python27\lib\site-packages\dateutil\tzwin.py", line 84, in __init__
    tzkey = winreg.OpenKey(handle, "%s\%s" % (TZKEYNAME, name))
WindowsError: [Error 2] The system cannot find the file specified

奇怪的是,代码在我的其他Windows机器上运行得很好。我有一种感觉,错误是一个配置错误的时区注册表,但我尝试过: http://support.microsoft.com/KB/2863058这永远不会返回

非常感谢任何帮助!

2 个答案:

答案 0 :(得分:2)

如果您传入的字符串与Windows注册表项不对应,则

tzwin.py会引发错误。要查看有效字符串,请将其粘贴到命令shell中:

reg.exe查询&#34; HKLM \ SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion \ Time Zones&#34;

我敢打赌,如果你在你的两台机器上运行它,你会看到那里的&#34;美国/太平洋地区&#34;在一个有效的,太平洋标准时间&#34;在那个失败的那个。试试这个:

timePST = timeNow.to(&#39;太平洋标准时间&#39;)

答案 1 :(得分:0)

根据此Google Groups post,降级到dateutil 2.2(pip install python-dateutil==2.2)可以解决问题。