无法从他们的日历中导入 UTC

Can't import UTC from icalendar

我尝试 运行 包含以下行的旧脚本:

from icalendar import UTC

这给了我以下错误:

Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
ImportError: cannot import name UTC

所以我查看了 icalendar 的更改日志,其中说明如下:

Renamed the UTC class to Utc, so it would not clash with the UTC object, since that rendered the UTC object unpicklable.

我将 UTC 更改为 Utc,但仍然出现相同的错误。

我怎样才能摆脱这个错误?

https://pypi.python.org/pypi/icalendartimezone support 部分中指出:

Instead of our own UTC tzinfo implementation we use pytz UTC tzinfo object now.

因此我建议您使用:

from pytz import UTC

...而不是:

from icalendar import UTC

Python 没有看到您的本地目录:

  1. 检查一下:

  2. 检查你的sys.path

    进口sys.path 打印 sys.path

如果这不是您的目录:

sys,path.insert(1, path)