Skip to content
root / How to Enable Virtual Environment In Python For Visual Studio Code

How to Enable Virtual Environment In Python For Visual Studio Code

In this article  let us see how to enable Virtual Environment In Python. So, Why virtual environment and why not the default Python? By default, If You install a Python package which is needed for one project, it would be available for whole of your computer. If you create any project, these packages will also be available for them. A virtual environment keeps a package within the project so that they are available only for that project. Follow the steps to create One.

Steps To Create Virtual Environment In Python

Type the following code in your terminal

$ sudo pip install virtualenv

So this will install the package for the virtual environment

2. Create a Folder to keep your venv

$ mkdir PyEnvironments

Go into  the folder using

$ cd PyEnvironments

3. Now add a  virtual environment using the following code
$ virtualenv project_1

4. Activating the virtual environment

$ source project_1/env/bin/activate

5. Installing other packages

pip install numpy

6. Converting the package into a txt file

pip freeze --local > rts.txt

After this you will see the following

This means that your virtual environment is running successfully if not check the steps.

Delete, Deactivate Virtual Environment

To deactivate the venv just type

$ deactivate

which will deactivate the virtual environment and you will see the result like this:

Delete the venv

To delete the folder in which the venv is present type:

$ rm -rf project_1

then the folder will be deleted

Happy Coding

Harshith Ashok

Tags: