Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Managing Isolated Python Dependencies with venv

Tech 1

For developers working on multiple Python projects requiring conflicting library versions, venv provides a solution for dependency isolation. This standard library module allows the creation of self-contained environments, each with its own independent set of installed packages, preventing conflicts between projects.

Creating a Virtual Environment

First, navigate to your project directory using a terminal. The following command creates a new environment:

python -m venv environment_name

For instance, executing this with in a project folder named project_a:

python -m venv project_a_env

A new directory named project_a_env will appear. This folder contains a complete, isolated Python installation and a dedciated package management directory (site-packages).

Activating the Environment

Activation methods differ between operating systems.

Windows Run the activation script from the command line:

project_a_env\Scripts\activate

macOS / Linux Use the source command to activate:

source project_a_env/bin/activate

Upon successful activasion, the terminal prompt will be prefixed with the environment name, e.g., (project_a_env). Any subsequent pip install commands will install packages only into this isolated environment.

Deactivating the Environment

To leave the virtual environment and return to the system's global Python context, execute:

deactivate

The environment prefix will disappear from the prompt, confirming the deactivation.

Tags: Python

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.