今天把當機已一個月的高雄 Pi 3B 主機重灌 Bulleye 後安裝爬蟲與資料科學相關套件後製作映像檔, 以免下次 TF 卡異常又要重來. 完成後想說來安裝 Gemini 新版 API 套件 google-genai (舊版是 google-generativeai 谷歌已不再維護), 雖然安裝成功, 但出現相依性問題 :
pi@kaopi3:~ $ pip install google-genai
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting google-genai
Downloading https://www.piwheels.org/simple/google-genai/google_genai-1.47.0-py3-none-any.whl (241 kB)
... (略) ...
Installing collected packages: websockets, tenacity, google-genai
Attempting uninstall: websockets
Found existing installation: websockets 12.0
Uninstalling websockets-12.0:
Successfully uninstalled websockets-12.0
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
gradio-client 1.3.0 requires websockets<13.0,>=10.0, but you have websockets 15.0.1 which is incompatible.
Successfully installed google-genai-1.47.0 tenacity-9.1.2 websockets-15.0.1
我把錯誤提交給 Gemini 分析, 原來 google-genai 需要最新版的環境所以把 websockets 從 12.0 版升級到了 15.0.1 版, 原本安裝的 gradio-client (1.3.0) 是一個比較挑剔的套件, 它要求 websockets 的版本必須在 10.0 到 13.0 之間 (不含 13), 現在提升 15.0.1 版了, 可能會讓 gradio 無法運作. 如果在樹莓派 Pi 3 上不會用到 gradio, 那這個錯誤訊息可以無視 (安裝 gradio 是因為它有一拖拉庫的相依套件例如 matplotlib, 並不是真的會用).
實測一下看看能否正常使用 :
pi@kaopi3:~ $ python
Python 3.9.2 (default, May 18 2026, 18:09:43)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from google import genai
/home/pi/.local/lib/python3.9/site-packages/google/auth/__init__.py:54: FutureWarning: You are using a Python version 3.9 past its end of life. Google will update google-auth with critical bug fixes on a best-effort basis, but not with any other fixes or features. Please upgrade your Python version, and then update google-auth.
warnings.warn(eol_message.format("3.9"), FutureWarning)
/home/pi/.local/lib/python3.9/site-packages/google/oauth2/__init__.py:40: FutureWarning: You are using a Python version 3.9 past its end of life. Google will update google-auth with critical bug fixes on a best-effort basis, but not with any other fixes or features. Please upgrade your Python version, and then update google-auth.
warnings.warn(eol_message.format("3.9"), FutureWarning)
此警告只是說 Python 3.9 實在太舊了而已.
>>> from dotenv import dotenv_values
>>> config=dotenv_values('.env')
>>> gemini_api_key=config.get('GEMINI_API_KEY')
>>> client=genai.Client(api_key=gemini_api_key)
>>> response=client.models.generate_content(
... model='gemini-2.5-flash',
... contents='你是誰?'
... )
>>> print(response.text)
我是一个大型语言模型,由 Google 训练。
可見此新版 Gemini API 在 Pi 3 上使用沒問題.
沒有留言 :
張貼留言