0

When I type echo $PYTHONPATH I get

/usr/lib/python3.6

But when I type python as user root I get

 File "/usr/lib/python3.6/site.py", line 183
file=sys.stderr)
    ^
SyntaxError: invalid syntax

What is the reason for this error ?

When I type python3.6 I get no errors. If this question needs to be moved to UNIX SE please let me know.

9
  • 1
    AFAIK, the default python on Ubuntu 18.04 is still python2.7 - the error suggests you're executing python2 with a PYTHONPATH that's only appropriate for python3 Jul 20, 2019 at 12:42
  • @steeldriver Thanks for your response. How can I fix the problem ?
    – gansub
    Jul 20, 2019 at 12:46
  • 1
    That depends - what are you trying to do? why (and how) did you set your PYTHONPATH as /usr/lib/python3.6? Jul 20, 2019 at 12:52
  • @steeldriver I guess I do not have to set it. If I unset the PYTHONPATH will the error go away ?
    – gansub
    Jul 20, 2019 at 12:55
  • I expect so ... Jul 20, 2019 at 12:57

1 Answer 1

2

The error you are getting is consistent with trying to run the python3.6/site.py file using python2.7:

$ python2.7 /usr/lib/python3.6/site.py
  File "/usr/lib/python3.6/site.py", line 183
    file=sys.stderr)
        ^
SyntaxError: invalid syntax

Since python2.7 is still the default for Ubuntu 18.04, you should avoid setting your PYTHONPATH to a python3-specific value.

1
  • This worked for me in a case where bzr under msys2 was giving this error. I guessed bzr was based on python 2, so I changed PYTHONPATH from lib/python3.8/site-packages to lib/python2.7/site-packages to fix the error (these dirs are not under /usr in msys2, but otherwise the issue is the same). May 12, 2020 at 1:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .