尝试使用以下命令安装urllib.request模块
sudo pip install urllib.request
但它回来了
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
我该如何安装这个模块?
urllib.request仅在python3分支中可用。有关详细信息,请参阅以下帖子。 urllib.request in Python 2.7
在python3中,您必须使用urllib3模块。
$ pip3 install urllib3
或者,如果您使用的是虚拟环境:
$ pip install urllib3
在python 2中,您只需使用urllib
import urllib
htmlfile=urllib.urlopen("your url")
htmltext=htmlfile.read()
在python 3中,您需要使用urllib.request
import urllib.request
htmlfile=urllib.request.urlopen("your url")
htmltext=htmlfile.read()
对于cmd中的Python3,
pip install urllib3
或者如果你使用的是anaconda:
conda install urllib3
希望对你有帮助