5

Help! i am getting this error again and again....on light table while i m trying to run python code

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

This is a code with installation.

Kevin
  • 74,910
  • 12
  • 133
  • 166
user3814582
  • 153
  • 2
  • 15
  • It looks as though you're trying to run Python 3 code under a Python 2 interpreter. – Mark Dickinson Jul 08 '14 at 16:48
  • What's the value of your `PYTHONPATH` environment variable? – Mark Dickinson Jul 08 '14 at 17:07
  • See also http://stackoverflow.com/q/20555517/270986 – Mark Dickinson Jul 08 '14 at 17:16
  • I was frustrated so i passed every possible path to all folders. Here what i have set the path....C:\Python34\Lib;C:\Python34\DLLs;C:\Python34\include;C:\Python34\libs;C:‌​\Python34\Scripts;C:\Python34\tcl;C:\Python34\Tools\pynche;C:\Python34\Tools\Scri‌​pts; Any suggestion would be appreciated.I have been using python 3 only so how it would use python 2 interpreter. – user3814582 Jul 09 '14 at 04:16
  • I don't know Light Table, but if it works like other Python-aware IDEs then there *should* be a place somewhere in its settings (or the settings for the Python plugin) where you tell it which Python interpreter you want to use. Did you find anything like that? – Mark Dickinson Jul 09 '14 at 05:54
  • One more thought: you might also look into the value of your `PATH` environment variable. It's possible that Light Table is (implicitly or explicitly) using that to find the Python interpreter to use. – Mark Dickinson Jul 09 '14 at 06:48
  • Thanks Mark but nothing seems to work. Which other tool will be good to use for python? Any suggestions. – user3814582 Jul 09 '14 at 16:21
  • Hmm. Post to the [Light Table mailing lists](https://groups.google.com/forum/?fromgroups#!forum/light-table-discussion), maybe? As to other tools, there are many free and non-free Python IDEs out there; a Google search would probably turn up better advice than I could give. – Mark Dickinson Jul 10 '14 at 19:49

1 Answers1

3

I have no idea about the Light Table part, but the error you show is the one that you'd get if you were to somehow try to execute a Python 3 print function call under Python 2 (where print is a statement with a quirky syntax rather than a function). Lines 175-176 of site.py in the Python 3.4 distribution look like this (modulo leading indentation):

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

and sure enough, if you try to execute that in a Python 2 interpreter you'll get a SyntaxError, with the cursor pointing to that same = sign:

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

I'd suggest looking closely at the settings for the Light Table Python plugin to see if anything's awry. You should also check the setting for your PYTHONPATH environment variable. If it includes a reference to the C:\Python34 directory and you're running Python 2, that could be the cause of the problem. Here's an example of the exact same problem on OS X, caused by starting Python 2 with a PYTHONPATH that refers to Python 3's library directory:

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
Mark Dickinson
  • 29,088
  • 9
  • 83
  • 120