0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Firebase initでPython仮想環境が作成できないエラーについて

0
Posted at

概要

エラー内容とその対処法のメモです。LLMに聞いてFirebaseのtutorialを進めていた際に発生したエラーですが、過去に失敗した内容を新しくひらめいたみたいに提案するのを繰り返し始めたので、オープンな形で対処法をメモに残します。

状況

場所 : GCP Cloud Shell
firebase --version : 15.32.0
python --version : 3.12.3

発生したエラー : firebase initで最後、typescript, javascript, pythonから言語を選ぶところでPythonを選んだ場合に以下のエラーが発生。

✔ What language would you like to use to write Cloud Functions? Python
i functions/requirements.txt is unchanged
i functions/.gitignore is unchanged
i functions/main.py is unchanged 

Error: Failed to create virtual environment. Please make sure Python is installed and in your PATH.

原因

firebase init --debugで内容を見ると分かるのですが、firebase CLIがpythonコマンドを3.14とバージョン指定で呼び出していました。

バージョン違いで過去に似た事例が報告されており、おそらく後続のバージョンでも同様に発生しうる事例だと思われます。

Firebase functions を python ではじめ…られない
Cloud Functions for FirebaseをPythonで使ってみた

解決法

方法は2種類あります。

1つ、環境に対応したPythonバージョンをいれること。これは上記2本の記事で対応されている方法です。

2つ目は、自身で仮想環境を作成する方法です。こちらでも問題なく後続のdeployまで動作しました。
firebase initコマンドの実行中にエラーが出ていますが、それまでの仮想環境以外の必要なファイルの生成は済んでいます。そのため、そこから自前で以下のように仮想環境を作成してやれば問題ないです。(firebase CLIの要求するバージョンと異なっていても問題ありません。)

以下、自分の実行したコード

# 1. functions ディレクトリに移動
cd ~/<project-directory>/functions

# 2. 手動で仮想環境 (venv) を作成
python3 -m venv venv

# 3. 仮想環境を有効化
source venv/bin/activate

# 4. 必要なライブラリをインストール
pip install firebase-functions firebase-admin google-genai

公式リンク

official reference : Firebase CLI リファレンス

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?