webmaster-kazu.com

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

【Python】Google Generative AI High level APIクライアント「google-generativeai」のインストール

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

【Python】Google Generative AI High level APIクライアント「google-generativeai」のインストールについて解説しています。

「google-generativeai(https://github.com/google/generative-ai-python)」は、Googleの大規模言語モデル PaLM API 用のPythonクライアントライブラリです。

■Python

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

■google-generativeaiをインストールする

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

pip install google-generativeai

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

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

py -3.10 -m pip install google-generativeai

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

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

Collecting google-generativeai

Downloading google_generativeai-0.1.0-py3-none-any.whl (122 kB)

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 122.9/122.9 kB 7.0 MB/s eta 0:00:00

Collecting google-ai-generativelanguage==0.2.0

Downloading google_ai_generativelanguage-0.2.0-py3-none-any.whl (113 kB)

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 113.3/113.3 kB ? eta 0:00:00

Collecting google-api-core[grpc]!=2.0.,!=2.1.,!=2.10.,!=2.2.,!=2.3.,!=2.4.,!=2.5.,!=2.6.,!=2.7.,!=2.8.,!=2.9.*,<3.0.0dev,>=1.34.0

Downloading google_api_core-2.11.1-py3-none-any.whl (120 kB)

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 120.5/120.5 kB 7.4 MB/s eta 0:00:00

Collecting proto-plus<2.0.0dev,>=1.22.0

Downloading proto_plus-1.22.2-py3-none-any.whl (47 kB)

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 47.9/47.9 kB 2.4 MB/s eta 0:00:00

Collecting protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.19.5

Downloading protobuf-4.23.3-cp310-abi3-win_amd64.whl (422 kB)

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 422.5/422.5 kB 5.3 MB/s eta 0:00:00

Collecting requests<3.0.0.dev0,>=2.18.0

Using cached requests-2.31.0-py3-none-any.whl (62 kB)

Collecting google-auth<3.0.dev0,>=2.14.1

Downloading google_auth-2.20.0-py2.py3-none-any.whl (181 kB)

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 181.5/181.5 kB 11.4 MB/s eta 0:00:00

Collecting googleapis-common-protos<2.0.dev0,>=1.56.2

Downloading googleapis_common_protos-1.59.1-py2.py3-none-any.whl (224 kB)

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 224.5/224.5 kB 4.6 MB/s eta 0:00:00

Collecting grpcio<2.0dev,>=1.33.2

Downloading grpcio-1.54.2-cp310-cp310-win_amd64.whl (4.1 MB)

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.1/4.1 MB 3.1 MB/s eta 0:00:00

Collecting grpcio-status<2.0.dev0,>=1.33.2

Downloading grpcio_status-1.54.2-py3-none-any.whl (5.1 kB)

Collecting urllib3<2.0

Using cached urllib3-1.26.16-py2.py3-none-any.whl (143 kB)

Collecting cachetools<6.0,>=2.0.0

Downloading cachetools-5.3.1-py3-none-any.whl (9.3 kB)

Collecting six>=1.9.0

Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)

Collecting rsa<5,>=3.1.4

Using cached rsa-4.9-py3-none-any.whl (34 kB)

Collecting pyasn1-modules>=0.2.1

Using cached pyasn1_modules-0.3.0-py2.py3-none-any.whl (181 kB)

Requirement already satisfied: certifi>=2017.4.17 in c:\program files\python310\lib\site-packages (from requests<3.0.0.dev0,>=2.18.0->google-api-core[grpc]!=2.0.,!=2.1.,!=2.10.,!=2.2.,!=2.3.,!=2.4.,!=2.5.,!=2.6.,!=2.7.,!=2.8.,!=2.9.*,<3.0.0dev,>=1.34.0->google-ai-generativelanguage==0.2.0->google-generativeai) (2023.5.7)

Requirement already satisfied: idna<4,>=2.5 in c:\program files\python310\lib\site-packages (from requests<3.0.0.dev0,>=2.18.0->google-api-core[grpc]!=2.0.,!=2.1.,!=2.10.,!=2.2.,!=2.3.,!=2.4.,!=2.5.,!=2.6.,!=2.7.,!=2.8.,!=2.9.*,<3.0.0dev,>=1.34.0->google-ai-generativelanguage==0.2.0->google-generativeai) (3.4)

Collecting charset-normalizer<4,>=2

Using cached charset_normalizer-3.1.0-cp310-cp310-win_amd64.whl (97 kB)

Collecting pyasn1<0.6.0,>=0.4.6

Using cached pyasn1-0.5.0-py2.py3-none-any.whl (83 kB)

Installing collected packages: urllib3, six, pyasn1, protobuf, grpcio, charset-normalizer, cachetools, rsa, requests, pyasn1-modules, proto-plus, googleapis-common-protos, grpcio-status, google-auth, google-api-core, google-ai-generativelanguage, google-generativeai

WARNING: The script normalizer.exe is installed in 'C:\Users\user_\AppData\Roaming\Python\Python310\Scripts' which is not on PATH.

Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

WARNING: The scripts pyrsa-decrypt.exe, pyrsa-encrypt.exe, pyrsa-keygen.exe, pyrsa-priv2pub.exe, pyrsa-sign.exe and pyrsa-verify.exe are installed in 'C:\Users\user_\AppData\Roaming\Python\Python310\Scripts' which is not on PATH.

Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

Successfully installed cachetools-5.3.1 charset-normalizer-3.1.0 google-ai-generativelanguage-0.2.0 google-api-core-2.11.1 google-auth-2.20.0 google-generativeai-0.1.0 googleapis-common-protos-1.59.1 grpcio-1.54.2 grpcio-status-1.54.2 proto-plus-1.22.2 protobuf-4.23.3 pyasn1-0.5.0 pyasn1-modules-0.3.0 requests-2.31.0 rsa-4.9 six-1.16.0 urllib3-1.26.16

Enterキーを押すと、インストールが開始され、上記のように「Successfully installed」と表示されます。これが表示されれば、google-generativeaiが正常にインストールされたことになります。今回は「WARNING(警告)」が表示されましたが、あくまで警告でありエラーではないので、無視しています。

なお、今回はgoogle-generativeaiのバージョン0.1.0をインストールしました。