Python: ImportError no module named urllib

早过忘川 提交于 2019-12-02 18:45:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!