Search Tutorials
--Ads--Setting Up VS Code, Jupyter and Anaconda for RAG
Install and configure VS Code, Jupyter notebooks and Anaconda environments for RAG development.
You can build RAG applications with any editor, but three tools make the work much easier: VS Code for writing and debugging code, Jupyter notebooks for experimenting with retrieval step by step, and conda environments (from Anaconda or Miniforge) for managing Python and scientific packages. This lesson sets up all three and connects them to the same environment.
What you will learn
- When to use a plain virtual environment and when to use conda
- How to create a conda environment for RAG work
- How to set up VS Code for Python and notebooks
- How to run Jupyter with the right environment and load API keys in a notebook
Prerequisites
venv or conda?
| venv + pip | conda | |
|---|---|---|
| Comes with Python | Yes | No (install Anaconda, Miniconda or Miniforge) |
| Manages the Python version | No | Yes |
| Non-Python libraries (CUDA, MKL) | No | Yes |
| Best for | Applications and deployment | Data science and GPU work on your machine |
Both work for this tutorial. If you are unsure, the venv setup from the previous lesson is enough.
Option A: conda environment
Miniforge is a minimal installer that uses the community conda-forge channel; Anaconda is a larger distribution with many packages pre-installed. Organisations should check the licence terms of the Anaconda distribution and its default package channel before using them commercially. After installing either one, open a terminal (on Windows, the "Miniforge Prompt" or "Anaconda Prompt"):
conda create -n rag python=3.12 -y
conda activate rag
pip install -r requirements.txt # the tutorial's requirements file
pip install jupyterlab ipykernel
Using pip inside a conda environment is fine for packages that are not on conda channels; install conda packages first, then pip packages.
Option B: venv (from the previous lesson)
pip install jupyterlab ipykernel
Register the environment as a Jupyter kernel
A kernel is the Python process a notebook runs in. Register your environment so notebooks use the same packages:
python -m ipykernel install --user --name rag --display-name "Python (rag)"
Set up VS Code
- Install VS Code from code.visualstudio.com.
- Install the Python and Jupyter extensions published by Microsoft.
- Open your project folder (File > Open Folder).
- Press Ctrl+Shift+P (Cmd+Shift+P on macOS), run Python: Select Interpreter and choose your
ragenvironment or.venv. - Open a terminal in VS Code (Ctrl+`); it activates the selected environment automatically.
Useful settings: enable format-on-save with a formatter such as Black or Ruff, and use the built-in debugger (F5) to step through retrieval code and inspect retrieved chunks.
Use notebooks for RAG experiments
Notebooks are ideal for trying chunk sizes, inspecting embeddings and comparing retrieval results interactively. Start JupyterLab from the activated environment:
jupyter lab
Or create a .ipynb file in VS Code and pick the "Python (rag)" kernel at the top right. Load API keys from .env in the first cell:
%load_ext dotenv
%dotenv
Then check the environment:
import sys, os
print(sys.executable) # should point inside your rag environment
print("Anthropic key loaded:", bool(os.getenv("ANTHROPIC_API_KEY")))
C:\Users\you\miniforge3\envs\rag\python.exe
Anthropic key loaded: True
A recommended project layout
rag-project/
.env # API keys (git-ignored)
.gitignore
requirements.txt
rag_helpers.py # shared helpers
notebooks/ # experiments
src/ # application code (indexing, retrieval, API)
data/ # source documents (or a link to them)
tests/ # retrieval and answer tests
Move code from notebooks into src/ once it works; notebooks are for exploring, not for production code.
Common errors and troubleshooting
ModuleNotFoundErrorin a notebook but not in the terminal: the notebook uses a different kernel. Select the "Python (rag)" kernel.condanot recognised on Windows: use the Miniforge or Anaconda Prompt, or runconda initand reopen the terminal.- VS Code uses the wrong Python: run Python: Select Interpreter again; check the interpreter shown in the status bar.
%dotenvfails: installpython-dotenvin the same environment as the kernel.
Key takeaways
- Use venv for simple projects and conda when you need to manage Python versions or GPU libraries.
- Register your environment as a Jupyter kernel so notebooks and scripts share the same packages.
- In VS Code, always select the right interpreter; load secrets in notebooks with
%dotenv.
Frequently asked questions
Can I use Google Colab instead?
Yes, for experiments. Store keys in Colab's secrets feature rather than in notebook cells, and remember that uploaded documents leave your machine.
Do I need a GPU?
No. Hosted LLM APIs do the heavy work; small embedding models run fine on a CPU. A GPU helps for local LLMs and bulk embedding.
Practice exercises
- Create a notebook that embeds ten sentences and plots their similarity matrix as a heatmap.
- Set a breakpoint in a retrieval function in VS Code and inspect the scores in the debugger.