本文翻译自:ImportError: No module named requests
Whenever I try to import requests
, I get an error saying No module Named requests
. 每当我尝试导入requests
,都会收到一条错误requests
,提示“ No module Named requests
。
import requests
The error I get: 我得到的错误:
File "ex2.py", line 1, in <module>
import requests
ImportError: No module named requests
#1楼
参考:https://stackoom.com/question/1Acw4/ImportError-没有名为请求的模块
#2楼
Requests is not a built in module (does not come with the default python installation), so you will have to install it: Requests不是内置模块(默认的python安装不附带),因此您必须安装它:
OSX/Linux OSX / Linux
Use $ sudo pip install requests
(or pip3 install requests
for python3) if you have pip
installed 使用$ sudo pip install requests
(或pip3 install requests
为python3)如果你有pip
安装
Alternatively you can also use sudo easy_install -U requests
if you have easy_install
installed. 另外,您也可以使用sudo easy_install -U requests
如果您有easy_install
安装。
Alternatively you can use your systems package manager: 另外,您可以使用系统软件包管理器:
For centos: yum install python-requests
For Ubuntu: apt-get install python-requests
对于centos: yum install python-requests
对于Ubuntu: apt-get install python-requests
Windows 视窗
Use pip install requests
(or pip3 install requests
for python3) if you have pip
installed and Pip.exe added to the Path Environment Variable. 如果已安装pip
并将Pip.exe添加到路径环境变量,请使用pip install requests
(或python3的pip3 install requests
)。
Alternatively from a cmd prompt, use > Path\\easy_install.exe requests
, where Path
is your Python*\\Scripts
folder, if it was installed. 或者,在cmd提示符下,使用> Path\\easy_install.exe requests
,其中Path
是您的Python*\\Scripts
文件夹(如果已安装)。 (For example: C:\\Python32\\Scripts
) (例如: C:\\Python32\\Scripts
)
If you manually want to add a library to a windows machine, you can download the compressed library, uncompress it, and then place it into the Lib\\site-packages
folder of your python path. 如果您要手动将库添加到Windows计算机,则可以下载压缩的库,解压缩,然后将其放入python路径的Lib\\site-packages
文件夹中。 (For example: C:\\Python27\\Lib\\site-packages
) (例如: C:\\Python27\\Lib\\site-packages
)
From Source (Universal) 从来源(通用)
For any missing library, the source is usually available at https://pypi.python.org/pypi/ . 对于任何缺少的库,通常可从https://pypi.python.org/pypi/获得该源。 You can download requests here: https://pypi.python.org/pypi/requests 您可以在此处下载请求: https : //pypi.python.org/pypi/requests
On mac osx and windows, after downloading the source zip, uncompress it and from the termiminal/cmd run python setup.py install
from the uncompressed dir. 在Mac OS X和Windows上,下载源zip后,将其解压缩,然后从termiminal / cmd中运行python setup.py install
从未压缩的目录)。
#3楼
I had the same issue, so I copied the folder named "requests" from https://pypi.python.org/pypi/requests#downloads requests download to "/Library/Python/2.7/site-packages". 我遇到了同样的问题,因此我从https://pypi.python.org/pypi/requests#downloads 请求下载文件夹中将名为“ requests”的文件夹复制到“ /Library/Python/2.7/site-packages”。 Now when you use: import requests, it should work fine. 现在,当您使用:导入请求时,它应该可以正常工作。
#4楼
对于Windows,只需提供CD路径和python“脚本”路径,然后执行命令easy_install.exe
请求即可。然后尝试导入请求...
#5楼
If you are using Ubuntu, there is need to install requests
如果您使用的是Ubuntu,则需要安装requests
run this command: 运行以下命令:
pip install requests
if you face permission denied error, use sudo before command: 如果遇到权限被拒绝的错误,请在命令前使用sudo:
sudo pip install requests
#6楼
Adding Third-party Packages to the Application 向应用程序添加第三方程序包
Follow this link https://cloud.google.com/appengine/docs/python/tools/libraries27?hl=en#vendoring 跟随此链接https://cloud.google.com/appengine/docs/python/tools/libraries27?hl=zh_CN#vendoring
step1 : Have a file by named a file named appengine_config.py in the root of your project, then add these lines: 步骤1:在项目的根目录中有一个名为appengine_config.py的文件,然后添加以下行:
from google.appengine.ext import vendor 从google.appengine.ext导入供应商
Add any libraries installed in the "lib" folder. 添加安装在“ lib”文件夹中的所有库。
vendor.add('lib') vendor.add('lib')
Step 2: create a directory and name it "lib" under root directory of project. 步骤2:创建一个目录,并将其命名为project的根目录下的“ lib”。
step 3: use pip install -t lib requests 步骤3:使用pip install -t lib请求
step 4 : deploy to app engine. 第4步:部署到App Engine。