Quick Reference: The Python Project Lifecycle
Follow these steps every time you start a new coding session or a new project to ensure your Linux system stays clean and your code stays portable.
New Project Initialization
When starting a brand-new folder, run these once:
$ mkdir my_new_project && cd my_new_project
$ python3 -m venv venv
$ echo "venv/" >> .gitignore
Daily Development Workflow
Run these when you sit down to code:
$ source venv/bin/activate (Activate)
$ which python3 (Verify Path)
$ pip install [package_name] (Install Packages)
Sync Editor
Open VS Code and ensure the bottom-right status bar shows your `venv` interpreter.
Sharing & Portability
Before you push your code to GitHub:
Freeze Dependencies
$ pip freeze > requirements.txt
Commit
Ensure `requirements.txt` is committed, but `venv/` is ignored.
Moving to a New Machine
If you just cloned a project and need to get it running:
Create the local sandbox
$ python3 -m venv venv
Activate it
$ source venv/bin/activate
Install the recorded dependencies
$ pip install -r requirements.txt
The "Emergency" Command
If your environment ever gets weird or you get conflicting version errors, don't panic. Just delete the folder and start over:
$ rm -rf venv && python3 -m venv venv
It’s the "Turn it off and back on again" of Python development.