Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
473 views
in Technique[技术] by (71.8m points)

python - ImportError:没有名为请求的模块(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
  ask by user2476540 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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从未压缩的目录)。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...