Python Vibe Coding Course — Part 4

Ensuring Reproducibility

Preserve your environment with requirements.txt

By the end of Part 3, your analysis runs on your own PC. The next important step is to leave the environment in a form that third parties — co-authors, reviewers, or your future self — can reproduce. In Python, the standard approach is to export your libraries and their versions into a single text file called requirements.txt. This part explains how to create it and how others can use it to replicate your setup.

01 Why requirements.txt is necessary

As explained in Part 1, Python code only runs when the Python version and the set of library versions all match. Code you wrote using pandas 2.2.0 may not work in someone else's environment that only has pandas 1.5.0.

requirements.txt is a text file that lists each library you used along with its version, one per line. With this file, anyone who receives it can install exactly the same versions of all libraries with a single command.

Example contents of requirements.txt

pandas==2.2.0
openpyxl==3.1.2
matplotlib==3.8.2
numpy==1.26.3
seaborn==0.13.1

02 Generate requirements.txt

With your virtual environment active (the one you created in Part 2 as .venv), run the following command in the terminal.

Quick reminder: how to activate the virtual environment

Open a terminal in VSCode (top menu: Terminal → New Terminal), then run one of the following:
· Windows (PowerShell): .venv\Scripts\Activate.ps1
· Windows (Command Prompt): .venv\Scripts\activate.bat
· Mac / Linux: source .venv/bin/activate

When (.venv) appears at the start of the prompt, the virtual environment is active.

With the virtual environment active, run the following command:

Terminal (run with (.venv) shown in prompt)
pip freeze > requirements.txt

When the command completes successfully, a file named requirements.txt will appear at the root of your project folder. Open it and you will see all libraries currently installed in your virtual environment, each listed with its version.

Your folder structure at this point

my_first_analysis/
├── .venv/
├── analysis.ipynb
├── sample_data.xlsx
├── results/
└── requirements.txt   # ← newly created

Whenever you install a new library as your analysis grows, you will need to update requirements.txt. Make a habit of running pip freeze > requirements.txt one more time at the very end.

03 Steps for a third party to reproduce your environment

For a co-author or reviewer to reproduce your analysis, the folder you hand over plus some instructions is all that's needed. Let's start by clarifying what to include.

Files and folders to share

Contents of the shared folder

my_first_analysis/
├── data/             # Raw data (shareable items only)
├── analysis.ipynb   # Analysis script
├── results/       # Output figures/tables (include for reference)
├── requirements.txt  # Created in Step 2
└── README.md      # Instructions (created in Step 4 below)

Note: the .venv/ folder is not included. The recipient will regenerate it on their own PC.

You can share the folder however you like: zip it and send by email, share via cloud storage, or publish on GitHub or Zenodo as covered in Part 5.

Steps for the recipient

The person who receives your folder first checks the Python version written in README.md, then verifies whether that version is installed on their PC.

  1. Open README.md and check the Python version (e.g., "Tested on Python 3.12")
  2. Check whether that version is installed: in a terminal run python --version (on Windows with multiple versions installed, try py --list). If it is missing, download and install the required version from python.org/downloads.
  3. Open the folder in VSCode and run the following commands in the terminal:
Terminal (run inside the received folder)
# Windows — using Python 3.12 py -3.12 -m venv .venv .venv\Scripts\Activate.ps1 pip install -r requirements.txt # Mac / Linux — using Python 3.12 python3.12 -m venv .venv source .venv/bin/activate pip install -r requirements.txt

The first line creates a virtual environment with the version specified in README.md. Omitting the version number would use the system default Python, which may behave differently. The final pip install -r requirements.txt installs all libraries at the exact versions listed.

The recipient can now reproduce the exact environment you ran analysis.ipynb in. Running the code will produce the same figures and statistics — that is reproducibility.

04 Write setup instructions in README.md

It is strongly recommended to include a README.md file in your folder. As the first thing a third party will read, it should contain content like the following:

README.md (example)
# Analysis Package for [Your Study Title] ## Setup ``` python -m venv .venv source .venv/bin/activate # Windows: .venv\Scripts\Activate.ps1 pip install -r requirements.txt ``` ## Running the Analysis Open `analysis.ipynb` in VSCode and run the cells from top to bottom. Results will be saved to the `results/` folder. ## Python Version Tested on Python 3.12.

README.md can be created and saved as a plain text file in VSCode or any text editor.

What is Markdown?

The symbols like # and ``` in the example above follow a formatting convention called Markdown. By adding a few simple symbols to plain text, you can express headings, code blocks, lists, and other formatting in a lightweight way. Services like GitHub, Zenodo, Notion, and Slack all support Markdown, and README.md files are automatically rendered on GitHub.

For a full reference, see the supplementary article "Markdown Quick Reference". At minimum, just knowing # (headings) and ``` (code blocks) is enough.

05 Caveats: toward complete reproducibility

requirements.txt is powerful, but there are a few things to keep in mind.

That said, using the output of pip freeze as-is is perfectly fine for a start. Don't aim for perfection — just make sure you have a requirements.txt at all.

06 Exclude .venv with .gitignore (optional)

When sharing your folder on GitHub, it is standard practice to exclude the .venv folder. It should be regenerated by the recipient, and it is also quite large. To exclude it, create a file named .gitignore at the root of your project folder with the following contents:

.gitignore
.venv/ __pycache__/ *.pyc .ipynb_checkpoints/

With this file in place, these files and folders will be automatically excluded when you upload to GitHub. Part 5 covers this in more detail.


What you can now do

In the final Part 5, we'll cover how to publish the folder you've built to Zenodo or GitHub, and add the link to your paper's Appendix to ensure full reproducibility of your research.

Prev — Part 3 ← Vibe Coding with LLM Index Next — Part 5 Publishing with Your Paper →