How to Freeze pip Modules Before Upgrading Python
Overview
If you are upgrading Python and want to reinstall all your previously installed modules, you can use pip freeze to capture your current environment and restore it later.
These examples assume Windows PowerShell.
Step 1 – Freeze Your Current Environment
python -m pip freeze > requirements.txt
If multiple versions are installed:
py -3.12 -m pip freeze > requirements.txt
Step 2 – Install or Upgrade Python
py -3.13 --version
Step 3 – Reinstall All Modules
py -3.13 -m pip install -r requirements.txt
Recommended: Use a Virtual Environment
python -m venv .venv
\.venv\Scripts\Activate.ps1
pip freeze > requirements.txt
Recreate after upgrade:
py -3.13 -m venv .venv
\.venv\Scripts\Activate.ps1
pip install -r requirements.txt
Final Recommendation
- Always use virtual environments
- Commit requirements.txt to version control
- Recreate environments instead of copying site-packages