DEV Community

Sujith V S
Sujith V S

Posted on

Setup python virtual environment in linux

Image description
Virtual environment is a very important tool to isolate each project modules and dependencies from other projects in our system.
Let's see how to setup python virtual environment in a linux based system.

1) First let's install virtualenv module. Open the terminal and type the below command.
$ pip install virtualenv

2) Then let's check if our virtualenv installation is successful.
$ virtualenv --version
And it should show the version and location of the virtualenv installation.
virtualenv 20.13.0 from /usr/local/lib/python3.6/dist-packages/virtualenv/__init__.py

3) Now it's time to create a virtual environment.
Move to the folder where you want to setup your virtual environment and type the following command.
$ virtualenv my_venv
Here 'my_venv' is the name of the virtual environment. You can give any name as you like.

4) After creating a 'my_venv' named virtual environment in our project folder, now let's activate our virtual environment. Enter the following command to activate the virtual environment.
$ source my_venv/bin/activate

After activation the name of your virtual environment will appear in the left side of your terminal like this
(my_venv)

Now you can install dependencies required for our projects. And now your virtual environment will isolate all the dependencies that we have installed for this project.

Top comments (0)