Skip to content

Dear Internet Explorer user: Your browser is no longer supported

Please switch to a modern browser such as Microsoft Edge, Mozilla Firefox or Google Chrome to view this website's content.

Create a new Python environment on Linux

Easy steps for creating new Python environments in Windows Subsystem for Linux (WSL).

To create a new Python environment on Linux, open up your command prompt and install virtualenv as follows:

Creating the Environment

$ sudo pip3 install virtualenv

Create a new environment using virtualenv by setting a folder to contain it. The last part of the file path will contain the name of the environment (in this case, it will be called “adonline”):

$ python -m venv /home/amdimech/adonline

Activating the Environment

To activate the environment, enter the path of the environment:

$ source adonline/bin/activate

Different Versions of Python

If you require a different version of Python to be installed in your virtual environment to the one installed on your system, you will need to install that version first. This is achieved via the Deadsnakes respository, which can be installed as follows:

$ sudo apt update

$ sudo apt install software-properties-common

$ sudo add-apt-repository ppa:deadsnakes/ppa

Next, install the version of Python that you want (in this case, version 3.8):

$ sudo apt install python3.8

Next, you will need to install the virtual environment package for your version of Python. This is not installed when additonal versions of Python are installed.

$ sudo apt install python3.8-venv

Next, create a new environment that referneces the target version of Python. In this case, it will be called “adonline2” and will run Python 3.8.

$ virtualenv --python="/usr/bin/python3.8" "adonline2"

Within each environment, you can run the command python -V to see which version of Python is running.



No comments have yet been submitted. Be the first!

Have Your Say

The following HTML is permitted:
<a href="" title=""> <b> <blockquote cite=""> <code> <em> <i> <q cite=""> <strike> <strong>

Comments will be published subject to the Editorial Policy.