How to Create and Activate Virtual Environment In Linux ?
A short tutorial on creating and activating virtual environment on Linux .
In this short tutorial , I will be using Ubuntu Linux distro to explain the whole process of creating and activating virtual environment in Linux .
Creating virtual environment
Follow the steps below to create a virtual environment in your system .
- Open terminal in your Linux distro .You can directly press Ctrl + Alt +T to open terminal , or search ‘ terminal ’ after pressing super key and hit enter .
- Create a directory you wish to use as a virtual environment . Here , I am giving directory name as ‘ virenv ’ . Your are free to give any name to the directory as per your choice . To create the directory , type ‘ mkdir directory_name ’ in the terminal as shown in the screenshot below .
- Now , cd into the directory you just created by typing ‘ cd directory_name ’ as shown in the screenshot below .
- Type the below command in the terminal to create the virtual environment . Please ensure that you have Python 3 and virtualenv are installed in your system .
$ virtualenv -p python3 .
Please note that there is a dot at the end of the command which indicates that we are creating a virtual environment in the current directory . After the command is executed , you are done . Your virtual environment is created .
How to activate the virtual environment ?
Get into your virtual environment by typing the command below in the same directory in which you have just created it .
$ source bin/activate
And you are in .
Now , you can see the current directory name before the $ sign . This indicates that your virtual environment has been created . Here , you can keep you files and install specific version of libraries suited for your project .
Note — The specific version of library installed within the virtual environment will not be available outside it .
How to remove virtual environment ?
To remove virtual environment , simply delete the directory in which it is created . You can do this in the terminal by typing ‘ rm -rf directory name ’ .
$ rm -rf virenv
Thanks for reading.