Skip to main content

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
Secure Authentication
    In the top menu bar of the notebook editor, select Add-ons then Secrets. Create a new secret with the label GOOGLE_API_KEY. Paste your API key into the "Value" field and click "Save". 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