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

问题描述 投票:8回答:4

尝试使用以下命令安装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

我该如何安装这个模块?

python ubuntu pip urllib sudo
4个回答
14
投票

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


7
投票

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

$ pip3 install urllib3

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

$ pip install urllib3

6
投票

在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()

0
投票

对于cmd中的Python3,

pip install urllib3

或者如果你使用的是anaconda:

conda install urllib3

希望对你有帮助

© www.soinside.com 2019 - 2024. All rights reserved.