Python Virtual Environments for EWS

Overview

Follow these steps to create a custom python environment for your course. For more information about our Linux module system please visit https://answers.uillinois.edu/81201.

Creating a virtual python environment for use in EWS labs

These instructions go over the basics of creating a python virtual environment so that you can install packages to run on instructional lab machines and instructional remote resources like Fastx and Citrix. Since we do not give admin/root access to students on instructional machines this is the recommended method for installing packages you might need in your coursework. Please note that virtual environments are not portable so if you will need to use them on multiple lab machines we recommend creating your virtual environment inside your home directory so it will be accessible when you log into other instructional lab machines. 

On Linux Machines

Building a Virtual Environment


To get started you will need to load the python module first. If this is your first time using our module system you may want to review our article on how to use Linux Software Modules.

  1. To load the python module run the command:
    module load python3/3.12.10
  2. Now you can begin creating your own custom python install. To create a new virtual environment and save it to your home directory run the command:

    virtualenv <env-name> /home/netid/newvirtualenvironment

    
    

  3. To activate and begin using your virtual environment run the command:

    source <env-name>/bin/activate

    To activate and use your virtual environment saved in your home directory run the command:

    source /home/netid/<env-name>/bin/activate 

  4. Once you have your environment you can use the standard pip install to manage packages within that environment.

    pip install <package-name>

  5. To leave your virtual environment and return to your normal environment type the command: 
     
    deactivate



You can create multiple virtual environments as needed. As shown in the examples above the name of your current environment is printed before your bash prompt. This makes it easier to track where you are when working with multiple virtual environments.


Please Note: If a pip package install is dependent on system libraries which are absent, the install will fail and the libraries will need to be installed in the normal way (usually by the system administrator) before the pip package can be installed.

Exporting/Importing Virtual Requirements


You can export your virtual environment so that another person may load the exact same environment and test your code. To export your requirements.txt use the following steps:

  1. While your environment is activated run the following command:

    pip freeze > /path/to/text/file.txt

    If you are doing this from a virtual environment saved in your home directory the command would look something like this:

    pip freeze > /home/netid/yourenvironment.txt

  2. When another person wishes to load your environment they would run the following commands in the order shown:

    virtualenv <env-name>
    source <env-name> /bin/activate
    pip install -r /path/to/text/file.txt

  3. Alternatively if they would like to import your environment: 

    virtualenv /home/netid/import-env
    source import-env/bin/activate
    pip install -r /home/netid/my-env.txt

On Windows Machines

Building a Virtual Environment

  1. To use Python to create your virtual environment run this command:

    python -m venv myvenv
  2. Next change to the venv directories:

    cd myvenv

  3.  Load the virtual environment if you're in cmd:

    .\Scripts\activate.bat

    To load the virtual environment if you're in powershell:

    .\Scripts\activate.ps1
  4. Now you can install any packages you need in your virtual environment using pip:

    pip install packagename



Keywords:
base python load ews linux virtualenv pip install packages 
Doc ID:
81695
Owned by:
Manu P. in Engineering IT
Shared Services
Created:
2018-04-19
Updated:
2026-02-11
Sites:
University of Illinois Engineering IT