尝试在Python 3.4.0中导入请求模块时,收到以下错误:ImportError: No module named 'requests'
以前版本的Python中的requests
模块要求您单独使用pip
。但根据Python 3.4.0中的新功能,pip
内置于:https://docs.python.org/3.5/whatsnew/3.4.html#whatsnew-pep-453
我的导入行很简单:
import requests
我很困惑为什么这不起作用。非常感谢所有帮助。
答案 0 :(得分:5)
包含pip
意味着可以轻松检索新包。它没有说明通过pip可以访问的所有模块都捆绑在新的Python中(希望如此!)。
在使用包pip install requests
之前,您仍然需要requests
。
编辑:在another question之后,似乎对请求的依赖性存在缺陷。然后尝试:
pip install chardet2 urllib3
如提到的SO问题所示。
答案 1 :(得分:4)
答案可能here。
pip
:sudo apt-get install python3-pip
pip3
安装请求模块:pip3 install requests
如果您获得权限被拒绝错误,请在sudoers模式下运行上一个命令:sudo pip3 install requests
答案 2 :(得分:1)
虽然pip
是内置的,但您仍然需要致电pip install requests
。 pip
只是下载工具,而不是实际项目。要下载,请使用以下命令:
bash-3.2$ pip install requests
Downloading/unpacking requests
Downloading requests-2.2.1-py2.py3-none-any.whl (625kB): 625kB downloaded
Installing collected packages: requests
Cleaning up...
...
您不必安装pip
,但仍需使用它来安装其他项目。
回答您的评论,再次运行pip install
,这次使用sudo
。您应该看到以下消息:
$ sudo pip install requests
Password:
Requirement already satisfied (use --upgrade to upgrade): requests in /Library/Python/2.7/site-packages/requests-2.1.0-py2.7.egg
Cleaning up...
或类似的东西。然后运行:
>>> import requests
>>> requests
<module 'requests' from '/Library/Python/2.7/site-packages/requests-2.1.0-py2.7.egg/requests/__init__.pyc'>
>>>
如果import
失败,请转到上面的目录并搜索文件。