Skip to content
Advertisement

SyntaxError: invalid syntax upon importing modules

On my Debian distro, I am not sure if I corrupted my installation, but I get the following syntax error every time I import something with python.

My file:

JavaScript

Output:

JavaScript
JavaScript
JavaScript
JavaScript

What I also don’t understand is that error is referencing a totally different file (ssl.py), which I created previously and has nothing to do with the file I am running.

Any ideas how to resolve this?

Advertisement

Answer

import ssl should be reading something like /usr/lib/lib/python3/ssl.py. However, by creating your ssl.py in the same directory, you hijack it, and it gets loaded instead. The error comes from the fact that your ssl.py is written with Python 2 synax, and you are executing with a Python 3 interpreter (see print is a function). If this was corrected, you would likely have another error, because your ssl.py is probably not doing what requests is expecting ssl to do.

The solution is simple: remove the impostor ssl.py.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement