urllib.request模块无法在我的系统中安装

Mou*_*jan 10 python ubuntu sudo pip urllib

尝试使用以下命令安装urllib.request模块

sudo pip install urllib.request
Run Code Online (Sandbox Code Playgroud)

但它回来了

Downloading/unpacking urllib.request
  Could not find any downloads that satisfy the requirement urllib.request
Cleaning up...
No distributions at all found for urllib.request
Storing debug log for failure in /home/mounarajan/.pip/pip.log
Run Code Online (Sandbox Code Playgroud)

我该如何安装这个模块?

Koz*_*huk 15

urllib.request仅在python3分支中可用.有关详细信息,请参阅以下帖子. Python 2.7中的urllib.request


小智 7

在python3中,您必须使用urllib3模块.

$ pip3 install urllib3
Run Code Online (Sandbox Code Playgroud)

或者,如果您使用的是虚拟环境:

$ pip install urllib3
Run Code Online (Sandbox Code Playgroud)


小智 6

在python 2中,您只需使用urllib例如

import urllib
htmlfile=urllib.urlopen("your url")
htmltext=htmlfile.read()
Run Code Online (Sandbox Code Playgroud)

在python 3中,您需要使用urllib.request

import urllib.request
htmlfile=urllib.request.urlopen("your url")
htmltext=htmlfile.read()
Run Code Online (Sandbox Code Playgroud)