Python:导入错误,没有名为 urllib 的模块

发布于 2024-08-27 01:04:43 字数 264 浏览 7 评论 0原文

我刚刚从 Linode 租了一个 VPS,它有 python2.5 和 ubuntu 8.04。当我从 python shell 运行此命令时:

import urllib

我得到:

ImportError: No module named urllib

原因是什么?如何将此模块添加到 python 中?不是预装了基础版吗?

会不会是PYTHONPATH问题?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦纸 2024-09-03 01:04:44

好的,我解决了这个问题。
不知何故,python-tk 包(包括 urllib)丢失了。

所以下面的行解决了这个问题

apt-get install python-tk

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
莫相离 2024-09-03 01:04:44

我使用较新的操作系统,所以我不知道这是否有帮助,但以防万一:

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']
>>> 

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']
>>> 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文