问题
I just rented a VPS from Linode which has python2.5 and ubuntu 8.04. When I run this command from python
shell:
import urllib
I get:
ImportError: No module named urllib
What can be the reason? How can I add this module to python? Isn't it prepackaged with the basic version?
Can it be PYTHONPATH problem?
回答1:
Ok, I resolved the issue. Somehow, python-tk package (which includes urllib) was missing.
So the following line fixed the problem
apt-get install python-tk
回答2:
I use a later OS, so I don't know if this will help, but just in case:
marcelo@localhost:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 9.10
Release: 9.10
Codename: karmic
marcelo@localhost:~$ python
Python 2.6.4rc2 (r264rc2:75497, Oct 20 2009, 02:54:09)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib # works fine
>>> import sys
>>> sys.path
['', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/lib/python2.6/dist-packages', '/usr/local/lib/python2.6/dist-packages']
>>>
来源:https://stackoverflow.com/questions/2532321/python-importerror-no-module-named-urllib