Python

Set Up Python for Data Engineering

Install Python on Windows, macOS or Linux, set up VS Code, create a virtual environment, install packages with python -m pip and run your first data script.

By Javier GuerreroPublished 10 min readBeginner

Before you can clean a file, call an API or automate a load, you need a Python installation you can trust: one you can start from a terminal, that keeps each project’s packages separate, and that behaves the same way tomorrow as it does today. This lesson builds exactly that, step by step, and ends with a small script that checks your setup for you.

It is the first Python lesson of Stage 2 of the Become a Data Engineer roadmap. The two lessons that follow, and the pandas lessons after them, all start from the project folder you create here.

What you will learn

  • What Python is and why data engineers use it
  • How to install Python 3 on Windows, macOS or Linux and check that it works
  • How to set up Visual Studio Code with the Python extension
  • How to create a project folder and a virtual environment for it
  • How to install packages with python -m pip and record them in requirements.txt
  • How to run a Python script from the terminal and read the most common setup errors

Before you start

  • Prerequisites: a computer where you can install software, and basic comfort opening a terminal. No programming experience is needed.
  • Estimated time: 45–60 minutes, most of it downloads and installs.
  • Python version: install the latest stable Python 3 release from python.org. The code in these lessons was run with Python 3.14 and uses only features available since Python 3.10. Your version number will differ from the examples, and that is fine.

Commands differ between Windows and macOS/Linux, so each step shows both where they differ. On Windows, use PowerShell (it opens by default in the Windows Terminal and in VS Code). On macOS and Linux, use the Terminal app.

  1. 1Install Pythonpython.org, Homebrew or your Linux packages
  2. 2Install VS CodePlus the Python extension
  3. 3Create the project foldersales-pipeline with data and output
  4. 4Create a virtual environmentA private Python for this project
  5. 5Install packagespython -m pip install
  6. 6Run a scriptcheck_setup.py confirms everything
The setup you will build in this lesson

What Python is, and why data engineers use it

Python is a general-purpose programming language that reads almost like plain English. You write instructions in a text file that ends in .py, and the Python interpreter runs them line by line.

Data engineers use Python because it is the glue between systems. In a typical week you might use it to read a CSV export, check that every row has the fields you expect, call a web API, load results into a database, or orchestrate a Spark job. Python’s standard library (the modules that come with every installation) already covers files, CSV, dates, JSON and logging. Thousands of extra packages, such as pandas, extend it further.

Step 1: Install Python

Windows

  1. Go to python.org/downloads and download the Windows installer offered for the latest stable release. Recent releases provide the Python install manager, which installs Python and the py command. The same installer is also published in the Microsoft Store.
  2. Run the installer and accept the defaults. If you are offered an older-style installer with a checkbox named Add python.exe to PATH, tick it.
  3. Close every open terminal, then open a new PowerShell window so it picks up the new installation.

On Windows, the reliable command to start Python is py. Once a virtual environment is active (Step 5), you will use python instead.

macOS

Download the macOS installer from python.org/downloads and run it, or, if you already use Homebrew, run brew install python. On macOS the command is python3: the plain python command may not exist.

Linux

Most distributions already include Python 3. On Debian and Ubuntu, install the pieces you need for virtual environments with:

sudo apt update
sudo apt install python3 python3-venv python3-pip

On Fedora, use sudo dnf install python3. As on macOS, the command is python3.

Step 2: Check Python and pip

pip is the tool that installs packages. Check both:

# Windows PowerShell
py --version
py -m pip --version
# macOS / Linux
python3 --version
python3 -m pip --version

You should see a version number such as Python 3.14.0, and a line starting with pip followed by its version and install location. If you get an error instead, jump to Common setup errors.

Step 3: Install VS Code and the Python extension

You can write Python in any text editor, but Visual Studio Code gives you syntax highlighting, error hints and a built-in terminal in one window.

  1. Install VS Code from code.visualstudio.com.
  2. Open it, select the Extensions view in the left sidebar, search for Python and install the extension published by Microsoft.
  3. Open the integrated terminal with View → Terminal. On Windows it opens PowerShell by default.

You will connect VS Code to your project’s own Python in Step 5.

Step 4: Create the project folder

Every lesson in this series works in one folder called sales-pipeline. Create it with a data folder for input files and an output folder for results:

# Windows PowerShell
mkdir sales-pipeline
cd sales-pipeline
mkdir data, output
# macOS / Linux
mkdir sales-pipeline
cd sales-pipeline
mkdir data output

Now download the practice file, sales_transactions.csv, and save it inside the data folder. It holds 20 fictional sales from three stores, including some deliberately broken rows that the next lessons teach you to catch. The Sales Transactions Dataset page describes every column.

Finally, open the folder in VS Code with File → Open Folder… and choose sales-pipeline.

Step 5: Create and activate a virtual environment

A virtual environment is a private copy of Python for one project, with its own set of packages. Without one, every project on your computer shares the same packages, and upgrading a package for one project can break another. Data engineers create one per project, always.

Run this inside sales-pipeline:

# Windows PowerShell
py -m venv .venv
.\.venv\Scripts\Activate.ps1
# macOS / Linux
python3 -m venv .venv
source .venv/bin/activate

The first command creates a folder named .venv. The second activates it: your prompt now starts with (.venv). From now on, in this terminal, the command is simply python on every operating system, and it points to the project’s own interpreter:

python --version

To leave the environment, run deactivate. Activation only lasts for the current terminal, so activate again each time you open a new one.

Connect VS Code to it. Press Ctrl+Shift+P (Cmd+Shift+P on macOS), run Python: Select Interpreter and choose the entry that points to .venv. VS Code then uses this Python for running and checking your code, and new VS Code terminals usually activate the environment for you.

Step 6: Install packages with python -m pip

With the environment active, install pandas. You will not need it in the next two lessons, which use only the standard library, but the pandas lessons later in Stage 2 do:

python -m pip install pandas

Then list what is installed and save the list:

python -m pip list
python -m pip freeze > requirements.txt

pip list shows pandas and the packages it depends on, such as numpy. requirements.txt records their exact versions, so anyone, including you on another computer, can recreate the same environment with python -m pip install -r requirements.txt. Your version numbers will be different from anyone else’s, and that is expected.

Why python -m pip instead of just pip? Because it guarantees that the package goes into the Python you are running. A bare pip command can belong to a different installation, which is the most common cause of “I installed it, but Python says the module does not exist”.

pip may print a notice that a newer pip is available. It is safe to follow it (python -m pip install --upgrade pip) or to ignore it.

Step 7: Write and run a script

In VS Code, create a new file in sales-pipeline named hello.py with one line:

print("Hello, data engineering!")

Run it from the terminal, from inside the project folder, with the environment active:

python hello.py
Hello, data engineering!

python hello.py tells the interpreter to run the file. The path is relative to the folder your terminal is in, which is why you run it from sales-pipeline. You can also click the Run button (▷) at the top right of the editor.

Understand the project structure

Your project now looks like this:

sales-pipeline/
├── .venv/                  private Python and packages (never edit or commit)
├── data/
│   └── sales_transactions.csv   input data
├── output/                 results your scripts will write
├── hello.py                your first script
└── requirements.txt        exact package versions for this project

This shape will carry through the series: inputs in data, results in output, code at the top level. Keeping inputs and outputs apart means a script can always regenerate its outputs without ever touching the original data.

Exercise: check your setup

Create check_setup.py in sales-pipeline with this code. It reports which Python is running, whether the virtual environment is active and whether the dataset is where the next lessons expect it:

import platform
import sys
from pathlib import Path

print(f"Python version: {platform.python_version()}")
print(f"Interpreter: {sys.executable}")

in_virtual_env = sys.prefix != sys.base_prefix
print(f"Virtual environment active: {in_virtual_env}")

data_file = Path("data") / "sales_transactions.csv"
print(f"Dataset found: {data_file.exists()}")

if in_virtual_env and data_file.exists():
    print("Setup complete. You are ready for the next lesson.")
else:
    print("Setup incomplete. Fix each line above that says False.")

Run it with the environment active:

python check_setup.py

Expected output. Your version and folder will differ; the last three lines should match:

Python version: 3.14.0
Interpreter: C:\Users\you\sales-pipeline\.venv\Scripts\python.exe
Virtual environment active: True
Dataset found: True
Setup complete. You are ready for the next lesson.

On macOS and Linux, the interpreter path ends in .venv/bin/python. The important part is that it is inside .venv.

What the code does. The import lines load three standard-library modules. sys.prefix is the folder of the Python that is running; inside a virtual environment it differs from sys.base_prefix, the installation the environment was created from. Path("data") / "sales_transactions.csv" builds a file path that works on every operating system. You will learn each of these properly in the next two lessons; for now, the goal is a green light.

Try it the other way. Run deactivate, then run the script again with py check_setup.py (Windows) or python3 check_setup.py (macOS/Linux). It now reports Virtual environment active: False and Setup incomplete. Activate the environment again before you continue.

Common setup errors and troubleshooting

  • Windows: Python was not found; run without arguments to install from the Microsoft Store… Windows ships a shortcut named python that only points to the Store. Use py instead, or turn the shortcut off in Settings → Apps → Advanced app settings → App execution aliases. Inside an active virtual environment, python always works.

  • py or python3 is not recognized. Python is not installed, or the terminal was opened before the installation finished. Open a new terminal; if it still fails, reinstall Python.

  • Windows: running scripts is disabled on this system when activating. PowerShell’s execution policy blocks the activation script. Allow locally created scripts for your user once, then activate again:

    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
  • macOS/Linux: python: command not found. Use python3 until the environment is active.

  • Debian/Ubuntu: ensurepip is not available when creating the environment. Install the venv package with sudo apt install python3-venv, delete the half-created .venv folder and run the command again.

  • error: externally-managed-environment when installing a package. Some systems refuse pip install into the system Python on purpose. Activate your virtual environment first; installs then go into .venv.

  • ModuleNotFoundError: No module named 'pandas'. The package was installed into a different Python. Check that the prompt shows (.venv) and that VS Code’s selected interpreter points to .venv, then install again with python -m pip install pandas.

  • can't open file … [Errno 2] No such file or directory. The terminal is in a different folder, or the file name is misspelled. Check the current folder with Get-Location (PowerShell) or pwd (macOS/Linux) and list its files with ls.

  • Dataset found: False. The CSV is not in data, or the browser saved it under another name such as sales_transactions (1).csv. Move or rename it to data/sales_transactions.csv.

Knowledge check

  1. Why should every project have its own virtual environment?
  2. How can you tell that a virtual environment is active in your terminal?
  3. Why is python -m pip install pandas safer than pip install pandas?
  4. Should the .venv folder be committed to Git? Why or why not?
  5. check_setup.py prints Dataset found: False. Name two things to check.

Answers

  1. So each project has its own packages and versions. Upgrading a package for one project cannot break another, and requirements.txt can describe the environment exactly.
  2. The prompt starts with (.venv), python --version works on every operating system, and check_setup.py reports Virtual environment active: True.
  3. python -m pip installs into the Python you are actually running. A bare pip may belong to another installation.
  4. No. It is large, specific to one computer and can always be recreated from requirements.txt.
  5. That the terminal is in the sales-pipeline folder, and that the file is saved as data/sales_transactions.csv with exactly that name.

Next lesson

Your computer is ready: Python, an editor, a project folder, a virtual environment and a dataset. In Python Essentials for Data Engineers, Part 1, you will use them to learn variables, lists, dictionaries, conditions and loops, and finish by calculating the revenue of the valid sales in the dataset without any extra packages.

Tags

  • Python
  • CSV
  • Dataset