Member-only story
How to Use Different Python Versions With Virtualenv
2 min readMay 29, 2024
Press enter or click to view image in full size![]()
Step 1: Install Virtualenv
First, ensure you have virtualenv installed. If not, you can install it using pip:
pip install virtualenvStep 2: Create a Virtual Environment
To create a virtual environment with a specific Python version, use the -p flag followed by the path to the desired Python executable. For example:
virtualenv -p python3.7 myenvThis command creates a virtual environment named myenv using Python 3.7.
Step 3: Activate the Virtual Environment
Activate the virtual environment using the appropriate command for your operating system:
On Windows:
myenv\Scripts\activate
On macOS/Linux:
source myenv/bin/activate
Step 4: Install a Different Python Version
If you haven’t already, install the desired Python version on your system. Then, create a new virtual environment using that version:
virtualenv -p python3.8 myotherenv