未在Light Table中执行的Python脚本显示错误

时间:2014-07-08 16:37:23

标签: python lighttable

帮助!我一次又一次地得到这个错误....在我试图运行python代码的光桌上

 File "C:\Python34\Lib\site.py", line 176
    file=sys.stderr)
        ^
SyntaxError: invalid syntax

这是一个安装的代码。

1 个答案:

答案 0 :(得分:2)

我不知道Light Table部分,但是如果你想以某种方式尝试在Python 2下执行Python 3 print函数调用,那么你显示的错误是你得到的错误(其中print是一个带有古怪语法而不是函数的语句。 Python 3.4发行版中site.py的第175-176行看起来像这样(模数前导缩进):

print("Error processing line {:d} of {}:\n".format(n+1, fullname),
      file=sys.stderr)

果然,如果您尝试在Python 2解释器中执行该操作,您将获得SyntaxError,光标指向同一个=符号:

Python 2.7.8 (default, Jul  3 2014, 06:13:58) 
[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Error processing line {:d} of {}:\n".format(n+1, fullname), file=sys.stderr)
  File "<stdin>", line 1
    print("Error processing line {:d} of {}:\n".format(n+1, fullname), file=sys.stderr)
                                                                           ^
SyntaxError: invalid syntax

我建议仔细查看Light Table Python插件的设置,看看是否有任何问题。您还应该检查PYTHONPATH环境变量的设置。如果它包含对C:\Python34目录的引用并且您正在运行Python 2,则可能是问题的原因。这是OS X上完全相同的问题的一个例子,它是由Python 2引用一个引用Python 3的库目录的PYTHONPATH引起的:

noether:~ mdickinson$ export PYTHONPATH=/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/
noether:~ mdickinson$ python2.7
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site.py", line 176
    file=sys.stderr)
        ^
SyntaxError: invalid syntax