Python 导入错误:没有名为请求的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17309288/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 07:50:57  来源:igfitidea点击:

ImportError: No module named requests

pythonpython-requestspython-import

提问by user2476540

Whenever I try to import requests, I get an error saying No module Named 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

回答by TheoretiCAL

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

操作系统/Linux

Use $ sudo pip install requests(or pip3 install requestsfor python3) if you have pipinstalled. If pip is installed but not in your path you can use python -m pip install requests(or python3 -m pip install requestsfor python3)

如果已安装,请使用$ sudo pip install requests(或pip3 install requests用于 python3) pip。如果 pip 已安装但不在您的路径中,您可以使用python -m pip install requests(或python3 -m pip install requests用于 python3)

Alternatively you can also use sudo easy_install -U requestsif you have easy_installinstalled.

或者,sudo easy_install -U requests如果您已经easy_install安装,您也可以使用。

Alternatively you can use your systems package manager:

或者,您可以使用系统包管理器:

For centos: yum install python-requestsFor 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 requestsfor python3) if you have pipinstalled and Pip.exe added to the Path Environment Variable. If pip is installed but not in your path you can use python -m pip install requests(or python3 -m pip install requestsfor python3)

如果您已安装并将 Pip.exe 添加到路径环境变量中,请使用pip install requests(或pip3 install requests用于 python3) pip。如果 pip 已安装但不在您的路径中,您可以使用python -m pip install requests(或python3 -m pip install requests用于 python3)

Alternatively from a cmd prompt, use > Path\easy_install.exe requests, where Pathis your Python*\Scriptsfolder, if it was installed. (For example: C:\Python32\Scripts)

或者,在 cmd 提示符下,使用> Path\easy_install.exe requestsPath您的Python*\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-packagesfolder of your python path. (For example: C:\Python27\Lib\site-packages)

如果你想手动添加一个库到windows机器,你可以下载压缩库,解压,然后放到Lib\site-packages你的python路径的文件夹中。(例如:C:\Python27\Lib\site-packages

From Source (Universal)

从源(通用)

For any missing library, the source is usually available at https://pypi.python.org/pypi/. You can download requests here: https://pypi.python.org/pypi/requests

对于任何缺失的库,源通常可从https://pypi.python.org/pypi/ 获得。你可以在这里下载请求: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 installfrom the uncompressed dir.

在 mac osx 和 windows 上,下载源 zip 后,将其解压缩,然后从终端/cmdpython setup.py install从未压缩的目录中运行。

(source)

来源

回答by bigboss21

I had the same issue, so I copied the folder named "requests" from https://pypi.python.org/pypi/requests#downloadsrequests downloadto "/Library/Python/2.7/site-packages". Now when you use: import requests, it should work fine.

我遇到了同样的问题,所以我将名为“requests”的文件夹从https://pypi.python.org/pypi/requests#downloads requests download复制到“/Library/Python/2.7/site-packages”。现在,当您使用:导入请求时,它应该可以正常工作。

回答by jazz

For windows just give path as cd and path to the "Scripts" of python and then execute the command easy_install.exerequests.Then try import requests...

对于 Windows,只需将路径作为 cd 和路径提供给 python 的“脚本”,然后执行命令easy_install.exe请求。然后尝试导入请求...

回答by Awais

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

回答by krishna kanth

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=en#vendoring

step1 :Have a file by named a file named appengine_config.py in the root of your project, then add these lines:

step1:在项目的根目录中有一个名为 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.

第二步:在项目的根目录下创建一个目录并命名为“lib”。

step 3:use pip install -t lib requests

第 3 步:使用 pip install -t lib requests

step 4 :deploy to app engine.

第 4 步:部署到应用引擎。

回答by Deming

To install requestsmodule on Debian/Ubuntu for Python2:

requests在 Debian/Ubuntu 上为 Python2安装模块:

$ sudo apt-get install python-requests

$ sudo apt-get install python-requests

And for Python3 the command is:

对于 Python3,命令是:

$ sudo apt-get install python3-requests

$ sudo apt-get install python3-requests

回答by SamPutnam

It's not obvious to me which version of Python you are using.

我不清楚您使用的是哪个版本的 Python。

If it's Python 3, a solution would be sudo pip3 install requests

如果是 Python 3,则解决方案是 sudo pip3 install requests

回答by Pi K

In my case requests was already installed, but needed an upgrade. The following command did the trick

在我的情况下, requests 已经安装,但需要升级。以下命令可以解决问题

$ sudo pip install requests --upgrade

回答by Sai Gopi N

On Windows Open Command Line

在 Windows 上打开命令行

pip3 install requests

回答by Pnet

you can also use pip install on windows by first locating the pip3.exe file in the directory: say for me==> cd c:\python34\scripts then run ==> pip3 install requests

您还可以通过首先在目录中找到 pip3.exe 文件来在 Windows 上使用 pip install: 对我说==> cd c:\python34\scripts 然后运行 ​​==> pip3 install requests