Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Configuring Python Virtual Environments Across Operating Systems

Tech 1

Windows Configuration

Execute the following commands to acquire the necessary packages:

bash python -m pip install virtualenv python -m pip install virtualenvwrapper-win

Define the directory for storing environments via system environment variables: Navigate to System Properties -> Environment Variables -> New System Variable.

  • Variable Name: WORKON_HOME
  • Variable Value: D:\PythonVenvs

Apply the changes by executing the batch script located in the Scripts directory of your Python installation: cmd C:\Python39\Scripts\virtualenvwrapper.bat

macOS and Linux Configuration

Install the required tools using the package manager: bash python3 -m pip installl virtualenv python3 -m pip install virtualenvwrapper

Locate the shell script: bash sudo find / -name virtualenvwrapper.sh

Copy the script to a universally accessible path: bash sudo cp /opt/python3.9/bin/virtualenvwrapper.sh /usr/bin/

Append the environment configuration to your shell profile (~/.zshrc or ~/.bashrc): bash export VENV_HOME="$HOME/py_venvs" export WORKON_HOME=$VENV_HOME source /usr/bin/virtualenvwrapper.sh

Reload the shell configuration: bash source ~/.zshrc

Establish a symbolic link for the base executable: bash sudo ln -s /opt/python3.9/bin/virtualenv /usr/bin/virtualenv

Common Operations

Provision a new isolated workspace using the default interpreter: bash mkvirtualenv project_alpha

Provision a workspace targeting a specific interpreter version: bash mkvirtualenv -p python3.8 project_beta

List all provisioned workspaces: bash workon

Switch to an active workspace: bash workon project_alpha

Install dependencies within the active workspace: bash pip install requests

Terminate the active workspace session: bash deactivate

Permanently remove a workspace (must be deactivated first): bash rmvirtualenv project_alpha

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.