Getting a syntax error when I type pthon on Ubuntu 18.04

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 Answer

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like