无法使用 PIP 或 easy_install,因为删除了 /etc/lib/python2.7/urllib.py

无法使用 PIP 或 easy_install,因为删除了 /etc/lib/python2.7/urllib.py

就像标题所说的那样,我通过按键发出了命令:

sudo rm /etc/lib/python2.7/urllib.py
sudo rm /etc/lib/python2.7/urllib2.py

问题就此开始,Ubuntu 仍然可以启动,但是当我现在想用 pip 或 easy_install 做任何事情时,我收到此错误:

.....
import sys, os.path, re, urlparse, urllib, urllib2, shutil, random, socket, cSt$
ImportError: No module named urllib

我怎样才能恢复它?

更新:

我根据以下答案重新安装了 python2.7萨迦但是当我使用 pip 命令搜索时出现以下问题:

Exception:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/pip-1.1-py2.7.egg/pip/basecommand.py", line 104, in main
    status = self.run(options, args)
  File "/usr/local/lib/python2.7/dist-packages/pip-1.1-py2.7.egg/pip/commands/search.py", line 34, in run
    pypi_hits = self.search(query, index_url)
  File "/usr/local/lib/python2.7/dist-packages/pip-1.1-py2.7.egg/pip/commands/search.py", line 48, in search
    hits = pypi.search({'name': query, 'summary': query}, 'or')
  File "/usr/lib/python2.7/xmlrpclib.py", line 1224, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1578, in __request
    verbose=self.__verbose
  File "/usr/lib/python2.7/xmlrpclib.py", line 1264, in request
    return self.single_request(host, handler, request_body, verbose)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1292, in single_request
    self.send_content(h, request_body)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1439, in send_content
    connection.endheaders(request_body)
TypeError: endheaders() takes exactly 1 argument (2 given)

任何帮助都将不胜感激。

答案1

如果你意外地删除或覆盖了包中的文件,一般的答案是:

  1. 找出你的文件属于哪个包

    dpkg-S urllib2.py

答案:

python2.7: /usr/lib/python2.7/urllib2.py
  1. 重新安装包

    sudo apt-get install --重新安装 python2.7

文件现已恢复

相关内容