pypa / pip

The Python package installer
https://pip.pypa.io/
MIT License
9.52k stars 3.02k forks source link

Installing simplejson breaks pip on Python 3.2 #1839

Closed mgeisler closed 10 years ago

mgeisler commented 10 years ago

I have a project (zerovm/zpm) where we try to maintain compatibility with Python 3.2. I discovered that pip becomes unhappy if simplejson is installed. We don't depend on simplejson ourselves, but a dependency does.

The problem is that pip depends on requests, which tries to import simplejson before it falls back on the stdlib json module. The simplejson project does not support Python 3.2 (it uses the u"..." syntax for strings). This makes the import fail with a SyntaxError:

$ virtualenv -p python3.2 venv32
$ source venv32/bin/activate
$ pip install simplejson
# ...
$ pip install anything-you-want
Traceback (most recent call last):
  File "/home/mg/tmp/venv32/bin/pip", line 7, in <module>
    from pip import main
  File "/home/mg/tmp/venv32/lib/python3.2/site-packages/pip/__init__.py", line 11, in <module>
    from pip.vcs import git, mercurial, subversion, bazaar  # noqa
  File "/home/mg/tmp/venv32/lib/python3.2/site-packages/pip/vcs/mercurial.py", line 9, in <module>
    from pip.download import path_to_url
  File "/home/mg/tmp/venv32/lib/python3.2/site-packages/pip/download.py", line 22, in <module>
    from pip._vendor import requests, six
  File "/home/mg/tmp/venv32/lib/python3.2/site-packages/pip/_vendor/requests/__init__.py", line 58, in <module>
    from . import utils
  File "/home/mg/tmp/venv32/lib/python3.2/site-packages/pip/_vendor/requests/utils.py", line 25, in <module>
    from .compat import parse_http_list as _parse_list_header
  File "/home/mg/tmp/venv32/lib/python3.2/site-packages/pip/_vendor/requests/compat.py", line 77, in <module>
    import simplejson as json
  File "/home/mg/tmp/venv32/lib/python3.2/site-packages/simplejson/__init__.py", line 114, in <module>
    from .encoder import JSONEncoder, JSONEncoderForHTML
  File "/home/mg/tmp/venv32/lib/python3.2/site-packages/simplejson/encoder.py", line 21
    ESCAPE = re.compile(u'[\\x00-\\x1f\\\\"\\b\\f\\n\\r\\t\u2028\u2029]')
                                                                       ^
SyntaxError: invalid syntax

I have reported the error to requests and I hope they will fix it. When they do, the vendor copy included with pip should be updated. So I guess this issue is mostly here to track this and help others who run into this problem.

dstufft commented 10 years ago

This should be fixed in the next version of pip since we've updated our copy of requests to 2.4.1.

hbsdev commented 10 years ago

I have this issue in a python 3.2 project. Can I manually overwrite requests with the new version?

hbsdev commented 10 years ago

I gave up on python 3.2 and installed 3.4 where everything works. Thank you.