Python3でRequestsモジュールをインストール、アンインストール

Python3でRequestsモジュールをインストール、アンインストールする手順について検証環境で試してみました。

 

Requestsは、 Python の HTTP 通信ライブラリで、あるシステムへのWEB APIへの接続で必要になったので、インストールすることになりました。Python には標準で urllib というライブラリがあるそうですが、Requestsのほうがシンプルとのことです。

 

ちなみに、実行環境はWindows Server 2016の評価環境です。

 

Python2とPython3での両方の環境で実行できるようにしています。共存させるために、Pythonランチャーを使っています。

 

そして、肝心のPython3でRequestsモジュールをインストール、アンインストール方法です。

 

インターネットに接続できる環境で実施しています。

 

 

■インストール手順

 

>pip install requests
Collecting requests
Downloading requests-2.24.0-py2.py3-none-any.whl (61 kB)
|████████████████████████████████| 61 kB 8.6 kB/s
Collecting chardet<4,>=3.0.2
Downloading chardet-3.0.4-py2.py3-none-any.whl (133 kB)
|████████████████████████████████| 133 kB 3.3 MB/s
Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1
Downloading urllib3-1.25.11-py2.py3-none-any.whl (127 kB)
|████████████████████████████████| 127 kB 652 kB/s
Collecting certifi>=2017.4.17
Downloading certifi-2020.6.20-py2.py3-none-any.whl (156 kB)
|████████████████████████████████| 156 kB 1.6 MB/s
Collecting idna<3,>=2.5
Downloading idna-2.10-py2.py3-none-any.whl (58 kB)
|████████████████████████████████| 58 kB 326 kB/s
Installing collected packages: chardet, urllib3, certifi, idna, requests
Successfully installed certifi-2020.6.20 chardet-3.0.4 idna-2.10 requests-2.24.0 urllib3-1.25.11

 

■アンインストール手順

 

>pip uninstall requests
Found existing installation: requests 2.24.0
Uninstalling requests-2.24.0:
Would remove:
c:\python38\lib\site-packages\requests-2.24.0.dist-info\*
c:\python38\lib\site-packages\requests\*
Proceed (y/n)? y
Successfully uninstalled requests-2.24.0

 

Successfullyと出ればどちらもインストール、アンインストールに成功していることになります。

 

ちなみにインターネットに接続できない場合は、以下のようにエラーがでます。

 

>pip install requests
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x0000015B9A670190>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/requests/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x0000015B9A6700A0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/requests/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x0000015B9A670370>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/requests/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x0000015B9A456DF0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/requests/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x0000015B9A67E190>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/requests/
ERROR: Could not find a version that satisfies the requirement requests (from versions: none)
ERROR: No matching distribution found for requests
WARNING: You are using pip version 20.1.1; however, version 20.2.4 is available.
You should consider upgrading via the 'c:\python38\python.exe -m pip install --upgrade pip' command.

 

オフライン環境の場合は、個別に準備しておく必要があります。

 

ロジクール ワイヤレスマウス 無線 マウスM185RD 小型 電池寿命最大12ケ月 M185 レッド 国内正規品 3年間無償保証