7

当我尝试使用 pip 安装 lxml 时,出现“对等连接重置”异常:

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

这仅在安装 lxml 时发生,其他模块通过 pip 安装没有问题。有人有同样的问题吗?

4

3 回答 3

8

尝试选择另一个 PyPI 镜像,或者直接:

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

或者通过让pip找到最好的镜子:

pip install --use-mirrors lxml
于 2012-12-14T12:36:00.080 回答
2

就我而言,是一个 ipv6 问题。一些镜像仍然没有完整的 ipv6 访问权限。

禁用 ipv6 并重试。

于 2017-07-04T08:44:25.350 回答
1

事实证明,我使用的镜像无法从网络访问。我解决它的方法是直接通过操作系统安装它:

$ apt-get install python-lxml

然后将其复制到我的虚拟环境中:

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

然后我将它放在我的虚拟环境中:

$ pip freeze
........
lxml==2.3.2
........
于 2012-12-14T13:11:17.803 回答