Python environments: reproduce an analysis on another laptop
In this article (7 sections)
A reproducible analysis needs more than a script that ran once. Another reader needs the interpreter and dependency information, the same input data, explicit execution steps and expected results that reveal whether the run succeeded correctly.
A virtual environment isolates project packages from other Python projects. It does not automatically preserve your source data, operating-system assumptions or business definitions.
Start with a small complete project
Download the Python reporting lab. It contains a synthetic CSV, report.py, tests and an actual verification-results.json. The project uses only Python's standard library and was checked on Python 3.12.0.
The input intentionally contains invalid records and an identical replay. January's accepted Paid population is four orders, two customers and INR 47.50. The overall input disposition is eleven records: seven accepted unique orders, three rejects and one replay.
Those controls make the exercise more informative than merely printing “script finished.”
Create an isolated environment
From the lab directory in Windows PowerShell:
python --version
python -m venv .venv
& '.\.venv\Scripts\python.exe' -m unittest -v test_report.pyOn a POSIX shell, the environment interpreter is normally .venv/bin/python. Use the interpreter path directly if activation is inconvenient; activation is not required to run that environment's Python.
Python's venv documentation explains environment creation and why environments should be recreated at the destination rather than copied as portable folders.
The lab was also tested in a newly created environment without third-party packages: all fifteen checks passed. That establishes this project's standard-library dependency claim on the checked interpreter, not compatibility with every Python release or operating system.
Run the report and interpret its exit status
& '.\.venv\Scripts\python.exe' report.py --input raw_orders.csv --output review-output --month 2026-01The supplied flawed input intentionally produces process exit code 2 and a labelled partial output because three records are rejected. Inspect summary.json and rejected_records.csv in review-output. Do not interpret the nonzero status as an unexplained crash, and do not ignore it in a scheduler.
Exit 0 means no records were rejected under this exercise's rules. Exit 1 represents a fatal input, schema, conflicting-key or filesystem problem. The output directory is explicit; use a new directory when preserving an immutable run snapshot.
Record what determines the result
The report records Python version and the SHA-256 hash of the exact input bytes it parsed. Keep the code version, command arguments and source contract with those fields.
For this lab, month=2026-01 and the Paid-only eligibility rule are as important as the interpreter. Running the same code over February correctly gives a different result.
A hash identifies a file snapshot but does not prove its business completeness or authenticity by itself. Keep the data dictionary and source provenance alongside it.
Add dependencies deliberately when the project grows
If a later analysis uses pandas or another package, record and test the chosen dependency versions using the project's dependency-management approach. A package list exported from a crowded global environment can include unrelated software and still fail to describe non-Python requirements.
Recreate the environment from the documented specification and run the tests. Do not claim reproducibility solely because a requirements file exists.
Keep secrets and machine-specific credentials out of versioned environment files. A reproducible public lab should use synthetic or appropriately permitted inputs and documented configuration rather than a reader's private account state.
Test from a clean starting point
Run the project from a fresh process without relying on notebook variables or previously generated files. Confirm that the expected input is present and that outputs are created through the documented command.
If a test fails on another machine, compare interpreter, dependencies, file encoding, paths and input hash before changing the business logic. A different input snapshot can explain a mismatch without any environment defect.
Exercise: recreate the lab environment in a different folder, run all fifteen checks and compare January's summary controls. Then change only the month argument and explain which outputs should change while the input hash stays the same.
NeuraPath's Data Analytics with Generative AI course connects Python analysis with repeatable delivery. A useful portfolio project lets another person verify the result from a clean start.
Continue learning
This article is part of the Python foundations for analysts sequence. Use the neighbouring tasks when you need the prerequisite or the next application.
- Continue with Python lists versus dictionaries in a reporting task.
- Then apply it in Write a Python function with a clear input contract.
Pankit Kumar has 10 years in Data Science & AI, building and shipping production systems in regulated pharma and clinical environments. He is a freelance trainer at Boston Institute of Analytics, AnalytixLabs and Scaler, and has taught this material to thousands of working professionals.
This article is part of our Data Analytics with Generative AI programme — 3–4 months. The full analyst stack — Excel, SQL, Power BI and Python pipelines — then a generative-AI layer you can prove is right.
Explore Data Analytics with Generative AI