当我尝试使用pip安装lxml时,我遇到异常“Connection 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
这只发生在安装lxml时,其他模块安装了pip没问题。有人有同样的问题吗?
答案 0 :(得分:7)
尝试直接选择另一个PyPI镜像:
pip install -i http://e.pypi.python.org/simple lxml
或者让pip
找到最好的镜子:
pip install --use-mirrors lxml
答案 1 :(得分:2)
事实证明我以某种方式使用的镜像无法从网络访问。我解决这个问题的方法是通过操作系统直接安装它:
$ 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
........
答案 2 :(得分:2)
就我而言,是一个ipv6问题。有些镜像仍然没有完整的ipv6访问权限。
禁用ipv6并重试。