Requests - 環境設定



本章我們將學習Requests的安裝。要開始使用Requests模組,我們首先需要安裝Python。因此,我們將進行以下操作:

  • 安裝Python
  • 安裝Requests

安裝Python

訪問Python官方網站:https://python.club.tw/downloads/ (如下所示),並點選適用於Windows、Linux/Unix和Mac OS的最新版本。根據您的64位或32位作業系統下載Python。

Python Download

下載完成後,點選.exe檔案,並按照步驟在您的系統上安裝python。

Python For Windows

python包管理器pip也會在上述安裝過程中預設安裝。為了使其在您的系統上全域性執行,請直接將python的路徑新增到PATH環境變數中。安裝開始時會有提示,請記得勾選“新增到PATH”複選框。如果您忘記勾選,請按照以下步驟新增到PATH。

要新增到PATH,請按照以下步驟操作:

右鍵單擊您的計算機圖示,然後點選屬性>高階系統設定。

將顯示如下所示的螢幕:

System properties

點選上面顯示的環境變數。將顯示如下所示的螢幕:

Environment Variables

選擇Path並點選編輯按鈕,在末尾新增您的python的路徑。現在,讓我們檢查python版本。

檢查python版本

E:\prequests>python --version
Python 3.7.3

安裝Requests

現在我們已經安裝了python,我們將安裝Requests。

安裝python後,python包管理器pip也會安裝。以下是檢查pip版本的命令。

E:\prequests>pip --version
pip 19.1.1 from c:\users\xxxxx\appdata\local\programs\python\python37\lib\site-
packages\pip (python 3.7)

我們已經安裝了pip,版本是19.1.1。現在,我們將使用pip安裝Requests模組。

命令如下:

pip install requests
E:\prequests>pip install requests
Requirement already satisfied: requests in c:\users\xxxx\appdata\local\programs
\python\python37\lib\site-packages (2.22.0)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\kamat\appdata\local\
programs\python\python37\lib\site-packages (from requests) (2019.3.9)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\use
rs\xxxxx\appdata\local\programs\python\python37\lib\site-packages (from requests
) (1.25.3)
Requirement already satisfied: idna<2.9,>=2.5 in c:\users\xxxxxxx\appdata\local\
programs\python\python37\lib\site-packages (from requests) (2.8)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:\users\xxxxx\appdata\
local\programs\python\python37\lib\site-packages (from requests) (3.0.4)

我們已經安裝了該模組,因此在命令提示符中顯示“Requirement already satisfied”(需求已滿足);如果未安裝,它會下載安裝所需的包。

要檢查已安裝的requests模組的詳細資訊,可以使用以下命令:

pip show requests
E:\prequests>pip show requests
Name: requests
Version: 2.22.0
Summary: Python HTTP for Humans.
Home-page: http://python-requests.org
Author: Kenneth Reitz
Author-email: me@kennethreitz.org
License: Apache 2.0
Location: c:\users\xxxxx\appdata\local\programs\python\python37\lib\site-package
S
Requires: certifi, idna, urllib3, chardet
Required-by:

Requests模組的版本是2.22.0。

廣告