diff --git a/docs/tech_docs/python_project.md b/docs/tech_docs/python_project.md new file mode 100644 index 0000000..9981d3c --- /dev/null +++ b/docs/tech_docs/python_project.md @@ -0,0 +1,72 @@ +# Python Project Setup Guide + +This guide outlines a repeatable framework for setting up Python projects using virtual environments and effective package management. + +## Setting Up a Virtual Environment + +1. **Create Project Directory** + ```bash + mkdir my_project && cd my_project + ``` + +2. **Create Virtual Environment** + ```bash + python3 -m venv venv + ``` + +3. **Activate Virtual Environment** + - macOS/Linux: + ```bash + source venv/bin/activate + ``` + - Windows: + ```cmd + .\venv\Scripts\activate + ``` + +4. **Deactivate Virtual Environment** + ```bash + deactivate + ``` + +## Package Management with pip + +1. **Install a Package** + ```bash + pip install package_name + ``` + +2. **Install Specific Version** + ```bash + pip install package_name==version + ``` + +3. **Upgrade a Package** + ```bash + pip install --upgrade package_name + ``` + +4. **Using a Requirements File** + - Install packages: + ```bash + pip install -r requirements.txt + ``` + - Freeze current packages to `requirements.txt`: + ```bash + pip freeze > requirements.txt + ``` + +## Managing Dependencies + +- Create a `requirements.txt` file in your project root. +- List dependencies and versions, e.g., `flask==1.1.2`. +- Use `pip freeze` to generate this file with current environment packages. + +## Best Practices + +- Always activate your virtual environment when working on the project. +- Regularly update your `requirements.txt` to reflect new dependencies. +- Include `venv` in your `.gitignore` file. +- Commit `requirements.txt` to version control. + +This guide provides a streamlined approach to setting up and managing Python projects, ensuring consistency and ease of use across development environments. \ No newline at end of file