How to Use Different Python Versions With Virtualenv

Muhammad Abdullah Arif
2 min readMay 29, 2024


Photo by Hitesh Choudhary on Unsplash

Step 1: Install Virtualenv

First, ensure you have virtualenv installed. If not, you can install it using pip:

pip install virtualenv

Step 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 myenv

This 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

Step 5: Verify the Python Version

Activate the new environment and check the Python version:

source myotherenv/bin/activate
python --version

Step 6: Install Packages

Now you can install any packages you need within each virtual environment. Remember that each environment is isolated, so you can switch between Python versions effortlessly.

That’s it! You’re all set to work with different Python versions using virtualenv. 🎉

Remember to replace python3.7 and python3.8 with the specific Python versions you want to use.


Feel free to explore more about virtual environments and Python version management

Click on the link below to discover a wealth of knowledge and explore a variety of engaging topics.

Medium Profile: Muhammad Abdullah Arif — Medium

Stay Up-to-Date with Muhammad Abdullah Arif’s Latest Publications — Subscribe Now! (

If you wish to offer your support, kindly click on the link below to treat me to a coffee! ☕️😊

I wish you all the best in your future endeavours.



Muhammad Abdullah Arif

Python developer. The facts are the facts but opinions are my own.