Python 导入错误:没有名为“请求”的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16265368/
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
ImportError: No module named 'requests'
提问by user1765369
Getting this error when trying to run a Python script. I have downloaded a requests-1.2.0 folder but I have no idea what to do with it. I've tried running the setup.py file contained in the download but it just opens a command terminal for a second and closes.
尝试运行 Python 脚本时出现此错误。我已经下载了一个 requests-1.2.0 文件夹,但我不知道如何处理它。我试过运行下载中包含的 setup.py 文件,但它只是打开命令终端一秒钟然后关闭。
I am running Python from my Windows desktop, not on a server or anything like that.
我从我的 Windows 桌面运行 Python,而不是在服务器或类似的东西上。
No idea what I'm doing here!
不知道我在这里做什么!
采纳答案by Corey Goldberg
from the root directory of the requests folder you downloaded, run:
从您下载的请求文件夹的根目录中,运行:
$ python setup.py install
then it will be installed system-wide, and your scripts may use "import requests"
然后它将在系统范围内安装,并且您的脚本可能会使用“导入请求”
回答by MikeHunter
You need to run setup.py with the "install" argument. That will install requests in the site-packages folder where it can be imported globally.
您需要使用“安装”参数运行 setup.py。这将在可以全局导入的站点包文件夹中安装请求。
Open a cmd window and navigate to the requests folder that you downloaded. Then type the following into the cmd window:
打开一个 cmd 窗口并导航到您下载的请求文件夹。然后在cmd窗口中输入以下内容:
C:\python27\python.exe setup.py install
You'll need to change the path to the python executable to match that for your system, of course.
当然,您需要更改 python 可执行文件的路径以匹配您的系统。
PS: You're going to love requests!
PS:你会喜欢请求的!
回答by Katriel
You need to install it for the same version of Python that you're using to run your script. The setup.pytells Python how to do that, so you can open up a command line to that directory (do you know how to do that?) and type python setup.py installto install it.
您需要为用于运行脚本的相同版本的 Python 安装它。该setup.py告诉Python中如何做到这一点,所以你可以打开一个命令行到该目录(你知道该怎么做?),然后键入python setup.py install安装它。
But there's a much easier way -- Python has an excellent package manager, called pip. You can use that to install any other Python packages that you want by typing pip install requestsat the command line. In particular, it will connect to the internet and work out what to download, then download and install it?
但是有一个更简单的方法——Python 有一个优秀的包管理器,叫做pip。您可以通过pip install requests在命令行中键入来使用它来安装您想要的任何其他 Python 包。特别是,它会连接到互联网并计算出要下载的内容,然后下载并安装它?

