All python and pip commands throwing syntax error

2019-08-17 02:39发布

问题:

Redis is imported as -

import redis

Redis When I try running the script -

python -

import redis
  File "/usr/lib/python2.6/site-packages/redis/__init__.py", line 1, in <module>
    from redis.client import Redis, StrictRedis
  File "/usr/lib/python2.6/site-packages/redis/client.py", line 3198
    return {decode(encode(k)): v for k, v in iteritems(data)}

Then I found that even running any pip command, I am getting the same error -

sudo pip uninstall pip
[sudo] password for sandeepan.nath: 
Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    load_entry_point('pip==7.1.0', 'console_scripts', 'pip')()
  File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 299, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 2229, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 1948, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "/usr/lib/python2.6/site-packages/pip/__init__.py", line 14, in <module>
    from pip.vcs import git, mercurial, subversion, bazaar  # noqa
  File "/usr/lib/python2.6/site-packages/pip/vcs/mercurial.py", line 10, in <module>
    from pip.download import path_to_url
  File "/usr/lib/python2.6/site-packages/pip/download.py", line 45, in <module>
    from pip._vendor.cachecontrol.caches import FileCache
  File "/usr/lib/python2.6/site-packages/pip/_vendor/cachecontrol/caches/__init__.py", line 15, in <module>
    import redis
  File "/usr/lib/python2.6/site-packages/redis/__init__.py", line 1, in <module>
    from redis.client import Redis, StrictRedis
  File "/usr/lib/python2.6/site-packages/redis/client.py", line 3198
    return {decode(encode(k)): v for k, v in iteritems(data)}
                                   ^
SyntaxError: invalid syntax