From 1c8dad63ad943bff3278486c609d9c9b8bab26c7 Mon Sep 17 00:00:00 2001 From: medusa Date: Sat, 13 Jan 2024 17:41:23 +0000 Subject: [PATCH] Update docs/tech_docs/Python-Virtual-Environments.md --- docs/tech_docs/Python-Virtual-Environments.md | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/docs/tech_docs/Python-Virtual-Environments.md b/docs/tech_docs/Python-Virtual-Environments.md index a031d7a..1ee1fb3 100644 --- a/docs/tech_docs/Python-Virtual-Environments.md +++ b/docs/tech_docs/Python-Virtual-Environments.md @@ -1,3 +1,68 @@ +# Python Virtual Environment Setup Guide + +This guide provides step-by-step instructions on setting up a Python virtual environment and managing dependencies for your project. + +## Creating a Virtual Environment + +1. **Navigate to Your Project Directory** + Open a terminal and navigate to the directory where your project is located. + ```bash + cd path/to/your/project + ``` + +2. **Create the Virtual Environment** + Use the `venv` module to create a virtual environment named `env`. + ```bash + python3 -m venv env + ``` + +## Activating the Virtual Environment + +1. **Activate the Environment** + Once the environment is created, you need to activate it. + ```bash + source env/bin/activate + ``` + After activation, your prompt will change to indicate that you are in the virtual environment. + +## Managing Dependencies + +1. **Create a Requirements File** + Create a `requirements.txt` file to keep track of project dependencies. + ```bash + touch requirements.txt + ``` + +2. **Freeze Installed Packages** + If you have already installed packages, you can list them in `requirements.txt`. + ```bash + pip freeze > requirements.txt + ``` + +3. **View the Requirements File** + To see the contents of `requirements.txt`, use the `cat` command. + ```bash + cat requirements.txt + ``` + +## Deactivating the Virtual Environment + +1. **Deactivate the Environment** + When you are done working in the virtual environment, deactivate it. + ```bash + deactivate + ``` + +## Tips + +- Always activate your virtual environment before working on your project. +- Use `pip` to install any new packages while the environment is active. +- Regularly update your `requirements.txt` file to reflect new dependencies. +- Remember to deactivate the virtual environment when you're finished. + +By following these steps, you can effectively manage your Python project's dependencies in a clean, isolated environment. + +--- ## Standard Directory Structure for Python Projects on Debian In a Python project, particularly on a Debian Linux system, it's important to follow a standard directory structure for organization and efficiency. Here is a recommended structure: