Reproducible Research › Module 4: Environments
Pinning versions
Lesson 2 of 3 · 2 min
Pinning means writing down the exact version of every package your project uses, so anyone can install the same ones.
Not pinned versus pinned
| Not pinned | Pinned |
|---|---|
| pandas | pandas==2.2.2 |
| scikit-learn | scikit-learn==1.5.1 |
| numpy>=1.20 | numpy==1.26.4 |
- pandas
- Pinned: pandas==2.2.2
- scikit-learn
- Pinned: scikit-learn==1.5.1
- numpy>=1.20
- Pinned: numpy==1.26.4
"pandas" installs whatever is newest today; a year from now, that's a different version.
Tools by language
- Python, pip: pip freeze > requirements.txt records everything installed.
- Python, modern tools: uv and Poetry create a lock file (uv.lock, poetry.lock) with exact versions automatically.
- Conda: conda env export > environment.yml.
- R: the renv package records versions in renv.lock.
- JavaScript: package-lock.json.
Good habits
- Use a separate environment per project (a virtual environment, or conda env), so projects don't interfere.
- Record the language version too (Python 3.11).
- Commit the requirements or lock file to Git.
- Recreate the environment from the file once, from scratch, to check it really works.
Random seeds count too
Set and record random seeds in your code, so randomness is repeatable, and note any GPU settings that affect determinism.
RememberPin exact versions in a file, keep one environment per project, and commit the file with your code.