• Home
  • Get Started
  • About
  • Services
    • Research Software
    • Research Datasets
    • Compute
    • Storage
  • Knowledge Base
  • FAQ
  • Resources
  • Contact Us
  • Home
  • Get Started
  • About
  • Services
    • Research Software
    • Research Datasets
    • Compute
    • Storage
  • Knowledge Base
  • FAQ
  • Resources
  • Contact Us
home/Knowledge Base/Slurm Batch Jobs/Creating a Python Virtual Environment

Creating a Python Virtual Environment

In this tutorial, you will create a virtual environment to use in Python. `virtualenv` is a tool to create isolated Python environments in your personal environment. `virtualenv` creates a folder that contains all the necessary executables to use the modules that a Python project would need.

Loading Python modules

Start a FastX Slurm srun interactive job to create and when running a Python virtual environment.

Type module avail and module load python/3.9.7 to load the Python module.

Creating a Virtual Environment

You will need the complete path to the Python executable for the version you want to use. Get Python executable path using the following command:

module show python/3.9.7

In this case, the complete Python executable is located at /gridapps/Python-3.9.7/bin/python. Note that we have appended a /python to the path.

Create a virtual environment by using the following command:

virtualenv -p /gridapps/Python-3.9.7/bin/python <your-path-to-project>

For example, to create a virtual environment in ~/bigdata/test-venv, you would use:

virtualenv -p /gridapps/Python-3.9.7/bin/python ~/bigdata/test-venv

A virtual environment is created. This is an isolated Python environment where you can install project-specific Python modules. You only need to create a virtual environment once per project. You can create as many as you would like for each new project, or even share environments if you want.

Activating the Virtual environment

Activate the virtual environment by navigating to it and running the following commands:

cd ~/bigdata/test-venv
source bin/activate

Installing Python modules

As you can see, the active virtual environment has changed. See what modules are installed using:

pip list

Install new modules using the pip install command:

pip install requests

Deactivating Python virtual environment

To deactivate the environment, type:

deactivate

Related Articles
  • Run RStudio on SLURM
  • Run XStata on SLURM
  • Install Local R Packages
  • Stata Tutorial
  • R Monte Carlo Simulation Tutorial
  • R Fitspline Tutorial

  Install Local R Packages

Run XStata on SLURM  

  • Home
  • Get Started
  • About
  • Services
  • Knowledge Base
  • FAQ
  • Resources
  • Contact Us
  • Copyright © 2023 Stern Center for Research Computing