Chapter 1 · Getting Started
Setting Up: Python, VS Code and Virtual Environments
- Page 2 of 23
- 3 min read
Before writing programs you need three things: Python itself, an editor to write code in, and a virtual environment to keep each project's libraries tidy. If you just want to start right now, skip to the Google Colab option at the end.
1. Install Python
Download Python from python.org/downloads. At the time of writing (October 2026) the newest version is Python 3.15. Everything in this tutorial works on Python 3.12 or newer.
- Windows: run the installer and tick "Add python.exe to PATH" on the first screen. Forgetting this box is the most common setup problem.
- macOS: use the installer from python.org (or Homebrew:
brew install python). - Linux: Python is usually already installed; install a newer one with your package manager if
python3 --versionshows something older than 3.12.
Check it worked by opening a terminal (Command Prompt / PowerShell on Windows, Terminal on macOS/Linux) and typing:
python --versionPython 3.15.0On macOS and Linux the command may be python3 instead of python. Use whichever one prints a version.
2. Install an editor: VS Code
You can write Python in any text editor, but a good one catches mistakes as you type. Install Visual Studio Code (free) and then its Python extension from Microsoft. You get colour highlighting, auto-complete and a ▶ button to run the current file.
3. Create a virtual environment
Libraries are installed with pip, Python's package installer. If you install everything into one global Python, different projects soon need different versions of the same library and start breaking each other. A virtual environment is a private folder of libraries for one project. Making one is a habit every professional has:
# 1. Make a folder for the project and go into it
mkdir python-for-ai
cd python-for-ai
# 2. Create a virtual environment in a folder called .venv
python -m venv .venv
# 3. Activate it
# Windows (PowerShell): .venv\Scripts\Activate.ps1
# macOS / Linux: source .venv/bin/activate
# 4. Install the libraries this tutorial uses
python -m pip install numpy pandas matplotlib requests openai python-dotenvWhen the environment is active, your terminal prompt starts with (.venv). Run deactivate to leave it. In VS Code, choose the interpreter inside .venv with Python: Select Interpreter so the ▶ button uses it.
Use
python -m piprather than plainpip. It guarantees that the libraries go into the Python you are actually running.
4. Run your first file
Create a file called hello.py containing:
print("Hello, AI!")Run it with python hello.py in the terminal (or press ▶ in VS Code):
Hello, AI!Two ways to run Python
| Way | How | Good for |
|---|---|---|
| Script file | python hello.py | Real programs you keep and run again |
| Interactive shell (REPL) | Type python alone, then type lines at >>> | Quick experiments; type exit() to leave |
No install at all: notebooks
A notebook mixes code, its output and notes in one page, run cell by cell. Data scientists use notebooks constantly. Google Colab gives you one in the browser for free, with NumPy, pandas and Matplotlib already installed — perfect if you are on a borrowed or school computer. You can also run notebooks locally with Jupyter (python -m pip install jupyterlab, then jupyter lab) or inside VS Code.