Getting a syntax error when running

I am running a Linux server (Linux 4.1.12-124.19.1.el7uek.x86_64 #2 SMP Wed Sep 5 13:41:16 PDT 2018 x86_64 x86_64 x86_64 GNU/Linux) with python 2.7.5 on it (DBAs want it to be 2.7.5 for their script) and trying to get pip and requests running.

I was having a problem getting pip on, because when I would try to install the epel-release , it would tell me “no package” named that. So I had to do

"yum install"

Which finally let me do

"yum install python-pip"

to get pip installed.

I then did

"python -m pip install requests"

to install requests.

It looked good, but when I run the test script that the DBAs gave me to check, it gives me this.

"Traceback (most recent call last):
  File "/mnt/EBS_Cloning_Repo/clone/scripts/", line 2, in <module>
    import requests
  File "/usr/lib/python2.7/site-packages/requests/", line 133, in <module>
    from . import utils
  File "/usr/lib/python2.7/site-packages/requests/", line 27, in <module>
    from . import certs
  File "/usr/lib/python2.7/site-packages/requests/", line 15, in <module>
    from certifi import where
  File "/usr/lib/python2.7/site-packages/certifi/", line 1, in <module>
    from .core import contents, where
  File "/usr/lib/python2.7/site-packages/certifi/", line 17
    def where() -> str:
SyntaxError: invalid syntax"

I did find that this could be caused by running just the python command, instead of one like python2, so I try redoing some of the commands with the python2 command with the same results.

I do have another server, running as it should with this, and I compared the files that it is pointing to, and seeing some missing information in them (diff output one request), but I am not sure what I can do with that information.

Please do not use Python 2 any more. Its support ended 2.5 years ago!

The problematic line: def where() -> str: shows type annotation syntax of Python 3 ( -> str) which is not understood by Python 2. The package certify which you have in your /usr/lib/python2.7/site-packages/ does not seem to support Python 2.

If you desperately need to use Python 2:

  • Use the latest version available (2.7.18).
  • You have to use older versions of libraries compatible with the obsolete Python 2.
  • …or if the maintainer of your Linux distribution still supports Python 2 on its own (probably RHEL?) you can solve the problem with the maintainer.

You have a version conflict, @learningtopython. Type hinting was introduced in Python 3.5.

From typing — Support for type hints — Python 3.10.4 documentation