Python:ImportError 没有名为 urllib 的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2532321/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python: ImportError no module named urllib
提问by Yury Lifshits
I just rented a VPS from Linode which has python2.5 and ubuntu 8.04. When I run this command from python
shell:
我刚从 Linode 租了一个 VPS,它有 python2.5 和 ubuntu 8.04。当我从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?
原因是什么?如何将此模块添加到python?基础版不是预装的吗?
Can it be PYTHONPATH problem?
可能是 PYTHONPATH 问题吗?
回答by Yury Lifshits
Ok, I resolved the issue. Somehow, python-tk package (which includes urllib) was missing.
好的,我解决了这个问题。不知何故,缺少 python-tk 包(包括 urllib)。
So the following line fixed the problem
所以以下行解决了问题
apt-get install python-tk
回答by Marcelo Cantos
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']
>>>