Update docs/tech_docs/Python-Virtual-Environments.md

This commit is contained in:
2024-01-09 07:04:45 +00:00
parent 154b9437c9
commit e4833245d7

View File

@@ -279,4 +279,41 @@ Using `.env` files for environment-specific settings is a best practice in Pytho
By following these practices, you can securely manage environment-specific settings in your Python projects, keeping sensitive information out of your source code.
---
# Recommended Python Project Structure with Virtual Environment
When setting up a Python project with a virtual environment, organizing your project's directory structure effectively is crucial. Below is an expanded explanation of a typical project structure:
## Project Directory: MyProject
### `MyProject/` - The Root Directory
- This is the main folder that contains your entire project. It's named after your project (`MyProject` in this case).
#### `.gitignore`
- This file tells Git which files or folders to ignore in your project.
- It's essential to include your virtual environment directory (`my_project_env/`) here to prevent it from being tracked by version control, as it contains system-specific settings and dependencies.
#### `my_project_env/`
- This is your virtual environment directory where dependencies and settings specific to this project are stored.
- It's created by running `python3 -m venv my_project_env` inside your root directory.
- This environment keeps your project's dependencies isolated from the global Python installation and other projects.
#### `src/`
- Short for "source", this directory contains all the source code of your project.
- It's a good practice to separate your code into this directory to keep it organized and distinguish it from other project files.
- Within `src/`, you can have various Python scripts and modules that make up your application.
#### `tests/`
- This folder contains all the test code for your project.
- Keeping tests in a separate directory helps in maintaining them distinctly from your actual project code.
- It typically includes unit tests, integration tests, and other test scripts.
#### `requirements.txt`
- This file lists all the Python dependencies required by your project.
- It's created by running `pip freeze > requirements.txt` inside your activated virtual environment.
- This file ensures that anyone who clones your project can install the exact same dependencies by running `pip install -r requirements.txt`.
This structure is just a guideline and can be adjusted based on the specific needs of your project. The key is to keep it organized and logical to facilitate easy navigation and collaboration.
---