From ff81a00ad67fe926d7d3752993f5789002b7634f Mon Sep 17 00:00:00 2001 From: Dita Aji Pratama Date: Sat, 3 Jan 2026 17:14:44 +0700 Subject: [PATCH] Updating venv docs --- _sidebar.md | 4 +--- pages/getting-starter.md | 2 +- pages/requirement/git.md | 3 +++ pages/requirement/venv.md | 20 +++++++++++++------- 4 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 pages/requirement/git.md diff --git a/_sidebar.md b/_sidebar.md index c4426f0..a9427e0 100644 --- a/_sidebar.md +++ b/_sidebar.md @@ -33,7 +33,5 @@ --> * Requirement - * git - * python - * pip + * [git](pages/requirement/git.md) * [venv](pages/requirement/venv.md) diff --git a/pages/getting-starter.md b/pages/getting-starter.md index 702e39d..1593fd2 100644 --- a/pages/getting-starter.md +++ b/pages/getting-starter.md @@ -2,7 +2,7 @@ ## Requirement -You need a `git`, `python`, `pip`, and [venv](pages/requirement/venv.md) before using CostaPy. +You need a [git](pages/requirement/git.md), `python`, `pip`, and [venv](pages/requirement/venv.md) before using CostaPy. Install them using the following commands on your `Debian` or `Ubuntu` system. diff --git a/pages/requirement/git.md b/pages/requirement/git.md new file mode 100644 index 0000000..b4f1f97 --- /dev/null +++ b/pages/requirement/git.md @@ -0,0 +1,3 @@ +# git + +Work in progress diff --git a/pages/requirement/venv.md b/pages/requirement/venv.md index dfd8a36..30365f9 100644 --- a/pages/requirement/venv.md +++ b/pages/requirement/venv.md @@ -1,15 +1,21 @@ # venv -- Why must `venv`? +## Why must `venv`? - `venv` is a module in Python that provides support for creating lightweight, isolated Python environments, known as virtual environments. Each virtual environment has its own installation directories and can have its own versions of Python packages, independent of the system-wide Python environment. +Modern Debian & Ubuntu follow `PEP 668`. This is why you see errors like `error: externally-managed-environment`. It literally means "This Python environment is managed by the OS. Don’t touch it with pip.". - When deploying a Python application, using a virtual environment ensures that only the required packages (and their specific versions) are bundled. This reduces the risk of deploying unnecessary packages or incompatible versions that could lead to runtime errors. +`venv` is a module in Python that provides support for creating lightweight, isolated Python environments, known as virtual environments. Each virtual environment has its own installation directories and can have its own versions of Python packages, independent of the system-wide Python environment. - Using `venv` is a widely accepted best practice in the Python community. It encourages good habits in dependency management, ensuring that projects are self-contained and reducing the potential for "dependency hell." +When deploying a Python application, using a virtual environment ensures that only the required packages (and their specific versions) are bundled. This reduces the risk of deploying unnecessary packages or incompatible versions that could lead to runtime errors. - When a project is no longer needed, deleting its virtual environment is straightforward and does not affect other projects or the system's Python environment. +Using `venv` is a widely accepted best practice in the Python community. It encourages good habits in dependency management, ensuring that projects are self-contained and reducing the potential for "dependency hell." -- Why I add `venv` on my `gitignore`? +When a project is no longer needed, deleting its virtual environment is straightforward and does not affect other projects or the system's Python environment. - Committing `venv` to Git is gross. Virtual environments can contain thousands of files and their size can be in gigabytes. Committing them to Git can overload and clutter your source code repo with unnecessary files and cause confusion for anyone trying to clone and run the source code on their machine. +## How it works? + +When you run `python3 -m venv your_venv_directory_name`, Python creates a directory for “A mini Python install just for this project”. When you activate it with `source .venv/bin/activate`, your shell is told "When I type `python` or `pip`, use the ones inside `.venv`", Nothing else changes. So, when you type `pip install requests`, it installs only inside `.venv`. Then, you can deactivate venv with `deactivate` command. + +## Why I add `venv` on my `gitignore`? + +Committing `venv` to Git is gross. Virtual environments can contain thousands of files and their size can be in gigabytes. Committing them to Git can overload and clutter your source code repo with unnecessary files and cause confusion for anyone trying to clone and run the source code on their machine.