Python相对导入导致syntaxerror:语法无效 [英] Python relative import causes syntaxerror: invalid syntax

查看:395
本文介绍了Python相对导入导致syntaxerror:语法无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将这个伟大的python模块 Python-Chrono 安装到我的python环境,但它至少与python 2.4.3和2.6.6失败,并出现以下错误消息:

I'm trying to install this great python module Python-Chrono to my python environment, but it fails at least with python 2.4.3 and 2.6.6 with the following error message:

Traceback (most recent call last): 
  File "setup.py", line 30, in ?
    import chrono
  File "/home/janne/python-chrono-0.3.0/chrono/__init__.py", line 22
    from . import calendar
         ^
SyntaxError: invalid syntax

设置使用相对导入机制,它应该工作得很好,但在我的环境中它会导致此错误。

The setup is using relative import mechanism and it should work just fine, but in my environment it causes this error.

有没有办法解决这个问题?您是否在项目中看到过这种行为?

Is there a way to get this fixed? Have you seen this kind of behaviour in your projects?

推荐答案

Python 2.4不支持该语法 - 它是在Python中引入的2.5。

Python 2.4 doesn't support that syntax - it was introduced in Python 2.5.

(您是否100%确定它在2.6中的消息失败?)

(Are you 100% sure that it's failing with that message in 2.6?)

这篇关于Python相对导入导致syntaxerror:语法无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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