webmaster-kazu.com

テクノロジー・データ分析・実践ログ・その他

Python用の非同期同時実行と I/O のためのライブラリ「Trio」のインストール

カテゴリ: Python【初歩から現場実務的なもの】

Python用の非同期同時実行と I/Oのためのライブラリ「Trio」のインストールについて解説しています。なお、I/Oは、Input/Outputの略で「入出力」を意味する。

「Trio(https://trio.readthedocs.io/en/stable/index.html)」は、並列化されたI/Oで同時に複数のことを行うプログラムを書くのを助けるための作られたライブラリです。

■Python

今回のPythonのバージョンは、「3.8.5」を使用しています。(Windows10)(pythonランチャーでの確認)

■Trioをインストールする

Trioをインストールを行いますが、今回はpipを経由してインストールを行うので、まずWindowsのコマンドプロンプトを起動します。

pip install trio

起動後、上記のコマンドを入力し、Enterキーを押します。

なお、今回は、pythonランチャーを使用しており、Python Version 3.8.5にインストールを行うために、バージョンの切り替えを行います。

py -3.8 -m pip install trio

切り替えるために、上記のコマンドを入力し、Enterキーを押します。

Defaulting to user installation because normal site-packages is not writeable

Collecting trio

Downloading trio-0.21.0-py3-none-any.whl (358 kB)

---------------------------------------- 359.0/359.0 kB 930.0 kB/s eta 0:00:00

Collecting cffi>=1.14

Using cached cffi-1.15.1-cp38-cp38-win_amd64.whl (178 kB)

Collecting sortedcontainers

Using cached sortedcontainers-2.4.0-py2.py3-none-any.whl (29 kB)

Requirement already satisfied: sniffio in c:\users\user_\appdata\roaming\python\python38\site-packages (from trio) (1.3.0)

Collecting attrs>=19.2.0

Using cached attrs-22.1.0-py2.py3-none-any.whl (58 kB)

Collecting outcome

Downloading outcome-1.2.0-py2.py3-none-any.whl (9.7 kB)

Requirement already satisfied: idna in c:\users\user_\appdata\roaming\python\python38\site-packages (from trio) (3.3)

Collecting async-generator>=1.9

Using cached async_generator-1.10-py3-none-any.whl (18 kB)

Collecting pycparser

Using cached pycparser-2.21-py2.py3-none-any.whl (118 kB)

Installing collected packages: sortedcontainers, pycparser, attrs, async-generator, outcome, cffi, trio

Successfully installed async-generator-1.10 attrs-22.1.0 cffi-1.15.1 outcome-1.2.0 pycparser-2.21 sortedcontainers-2.4.0 trio-0.21.0

Enterキーを押すと、インストールが開始され、上記のように「Successfully installed」と表示されます。これが表示されれば、trioが正常にインストールされたことになります。

なお、今回はtrioのバージョン0.21.0をインストールしました。