Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Configuring Python Virtual Environments Across Operating Systems

Tech Apr 19 10

Windows Configuration

Execute the following commands to acquire the necesary packages:

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:

C:\Python39\Scripts\virtualenvwrapper.bat

macOS and Linux Configuration

Install the required tools using the package manager:

python3 -m pip install virtualenv
python3 -m pip install virtualenvwrapper

Locate the shell script:

sudo find / -name virtualenvwrapper.sh

Copy the script to a universally accessible path:

sudo cp /opt/python3.9/bin/virtualenvwrapper.sh /usr/bin/

Append the environment configuration to your shell profile (~/.zshrc or ~/.bashrc):

export VENV_HOME="$HOME/py_venvs"
export WORKON_HOME=$VENV_HOME
source /usr/bin/virtualenvwrapper.sh

Reload the shell configuration:

source ~/.zshrc

Establish a symbollic link for the base executable:

sudo ln -s /opt/python3.9/bin/virtualenv /usr/bin/virtualenv

Common Operations

Provision a new isolated workspace using the default interpreter:

mkvirtualenv project_alpha

Provision a workspace targeting a specific interpreter version:

mkvirtualenv -p python3.8 project_beta

List all provisioned workspaces:

workon

Switch to an active workspace:

workon project_alpha

Install dependencies within the active workspace:

pip install requests

Terminate the active workspace session:

deactivate

Permanently remove a workspace (must be deactivated first):

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.