8

When I try to install lxml using pip I had the exception "Connection reset by peer":

Downloading/unpacking lxml
  Downloading lxml-3.0.1.tar.gz (3.2Mb): 643Kb downloaded
Exception:
Traceback (most recent call last):
  File "/home/dummyuser/work/virt-dev-env/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/basecommand.py", line 104, in main
    status = self.run(options, args)
  File "/home/dummyuser/work/virt-dev-env/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/commands/install.py", line 245, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "/home/dummyuser/work/virt-dev-env/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/req.py", line 985, in prepare_files
    self.unpack_url(url, location, self.is_download)
  File "/home/dummyuser/work/virt-dev-env/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/req.py", line 1109, in unpack_url
    retval = unpack_http_url(link, location, self.download_cache, self.download_dir)
  File "/home/dummyuser/work/virt-dev-env/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.py", line 451, in unpack_http_url
    download_hash = _download_url(resp, link, temp_location)
  File "/home/dummyuser/work/virt-dev-env/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.py", line 368, in _download_url
    chunk = resp.read(4096)
  File "/usr/lib/python2.7/socket.py", line 380, in read
    data = self._sock.recv(left)
  File "/usr/lib/python2.7/httplib.py", line 561, in read
    s = self.fp.read(amt)
  File "/usr/lib/python2.7/socket.py", line 380, in read
    data = self._sock.recv(left)
error: [Errno 104] Connection reset by peer

This only happened when installing lxml, other modules got installed with pip no problems. Anybody had the same problem?

Shengjie
  • 12,336
  • 29
  • 98
  • 139

3 Answers3

9

Try to choose another PyPI mirror, either directly:

pip install -i http://e.pypi.python.org/simple lxml

Or by letting pip find the best mirror:

pip install --use-mirrors lxml
  • yeah, now even just try to download it from pypi.python.org/simple, I hit network error. I guess something wrong with the mirror itself. – Shengjie Dec 14 '12 at 13:01
  • 1
    @Shengjie If *all* [PyPI mirrors](http://pypi.python.org/mirrors) fail it's more likely a problem on your end of the network. –  Dec 14 '12 at 13:07
  • I am getting lots of "Could not find a version that satisfies the requirement XX" – R Claven Apr 20 '17 at 18:56
  • Unfortunately it looks like `--use-mirrors` has been deprecated. It isn't available for me at all. See: https://stackoverflow.com/questions/28403263/canonical-replacement-for-use-mirrors – Stephen May 11 '23 at 22:10
2

In my case, was an ipv6 issue. Some mirrors still don't have full ipv6 access.

Disable ipv6 and try again.

Lauro Oliveira
  • 2,362
  • 1
  • 18
  • 12
1

It turns out the mirror I was using somehow is not accessible from the network. The way I got around with it is installing it via OS directly using:

$ apt-get install python-lxml

then copy it to my virtual env:

$ cp -r /usr/lib/python2.7/dist-packages/lxml* /home/dummyuser/work/virt-dev-env/local/lib/python2.7/site-packages/

I then have it in my virtual env:

$ pip freeze
........
lxml==2.3.2
........
Shengjie
  • 12,336
  • 29
  • 98
  • 139