Reference · How-to · ~8 min

How to set up a Python virtual environment

Isolate project packages so AI coding projects don't break your system Python.

Isolate project packages so AI coding projects don't break your system Python.

#Steps

1. Install Python 3.10+

2. Create a project folder

3. Create the venv

4. Activate it

5. Install packages with `pip` only while activated

#Commands

mkdir my-ai-app && cd my-ai-app
python3 -m venv .venv
source .venv/bin/activate   # Windows: .venv\Scripts\activate
pip install openai

#Verify

which python   # should point inside .venv
pip list

#Watch out

  • Commit `.venv` to git? **No** — add to `.gitignore`
  • Cursor/VS Code: select the `.venv` interpreter for AI terminal runs
  • **Try the lesson:** `python-virtual-environments` in Lane D