Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Like said on title, by a slip of the keys I issued the command:

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

And with that the problems started, Ubuntu still starts, but when I now want to do anything with pip or easy_install, I get this error:

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

How can I recover it?

UPDATE:

I reinstall python2.7 based on the answer of sagarchalise but when I search with pip comand then now I get following issue:

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)

Any help here would be appriciated.

share|improve this question
    
Try reinstalling python sudo apt-get install --reinstall python2.7 python2.7-minimal –  sagarchalise Aug 10 '12 at 7:21
add comment

1 Answer 1

up vote 2 down vote accepted

General answer if you accidentally remove or overwrite files from packages:

  1. Find out to which package your file belongs

    dpkg -S urllib2.py

Answers:

python2.7: /usr/lib/python2.7/urllib2.py
  1. Reinstall package

    sudo apt-get install --reinstall python2.7

File is now restored

share|improve this answer
    
Thanks all of you guys... I solved this issue by reinstall python2.7, pip, setuptools and distribute. –  pije76 Aug 10 '12 at 8:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.