python - Python3.6安装urllib

标签 python python-3.x urllib

我想导入 urllib 以使用函数“request”。但是,我在尝试这样做时遇到了错误。我试过 pip install urllib 但仍然有同样的错误。我正在使用 Python 3.6。非常感谢任何帮助。

我使用这段代码导入 urllib.request:

import urllib.request, urllib.parse, urllib.error 
fhand = urllib.request.urlopen('data.pr4e.org/romeo.txt') 
counts = dict()
for line in fhand: 
    words = line.decode().split() 
for word in words: 
    counts[word] = counts.get(word, 0) + 1 
print(counts) 

但它给了我这个错误:ModuleNotFoundError: No Module named 'urllib.parse'; 'urllib' 不是包

here is a screenshot for the error

最佳答案

urllib 是一个标准库,您不必安装它。只需导入 urllib

关于python - Python3.6安装urllib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47730259/

相关文章:

python - Python的httplib和urllib2有什么区别?

python - 数据未插入到 Flask sqlalchemy 中

python - __init__() 需要 1 个位置参数,但 2 个给出了类型错误

python - 从 Python 3 中的文件生成的列表中查找字符串

python - 为什么在我的类里面使用 __slots__ 不会改变大小?

python - 如何实现这个python post并获取?

python - 高效统计 NumPy 中唯一子数组的出现次数?

python - 将 SQL 记录从一个数据库插入到第二个数据库(其中第二个数据库有一个附加列)

python - VS 代码 : how to make a python snippet that after string or expression hitting tab will transform it

python - For循环调用urllib.urlopen().getcode()很慢