Jupyter Notebook

Installation

With pip

pip install notebook
Python Virtual Environment

With Python Venv

mkdir my-rag
cd my-rag
python -m venv .venv
source .venv/bin/activate
(my-rag)> pip install --upgrade pip
(my-rag)> pip install notebook
(my-rag)> jupyter notebook

With Conda

conda create -n my-rag python=3.10
conda activate my-rag
(my-rag)> pip install --upgrade pip
(my-rag)> pip install notebook
(my-rag)> jupyter notebook

UI 可切換不同虛擬環境(需要先建立不同的 ipykernel)

mkdir my-rag
cd my-rag
python -m venv .venv
source .venv/bin/activate
(my-rag)> pip install --upgrade pip
(my-rag)> pip install ipykernel
(my-rag)> ipython kernel install --user --name="my-rag-kernel"
(my-rag)> jupyter notebook

Tips

Secure Authentication
  1. In the top menu bar of the notebook editor, select Add-ons then Secrets.
  2. Create a new secret with the label GOOGLE_API_KEY.
  3. Paste your API key into the "Value" field and click "Save".
  4. Ensure that the checkbox next to GOOGLE_API_KEY is selected so that the secret is attached to the notebook.
import os
from kaggle_secrets import UserSecretsClient

try:
    GOOGLE_API_KEY = UserSecretsClient().get_secret("GOOGLE_API_KEY")
    os.environ["GOOGLE_API_KEY"] = GOOGLE_API_KEY
    print("✅ Gemini API key setup complete.")
except Exception as e:
    print(
        f"🔑 Authentication Error: Please make sure you have added 'GOOGLE_API_KEY' to your Kaggle secrets. Details: {e}"
    )

Resources

CoLab by Google


Revision #15
Created 2024-06-21 13:10:11 CST by A-Lang (Admin)
Updated 2025-11-17 14:49:13 CST by A-Lang (Admin)