How To Create And Use Python Virtual Environments

Hasmukh Mer
3 min readJan 1, 2023

--

Photo Taken From Google

Hello Learners..!!!

Welcome to my blog.

So Let’s Start…

What is a python virtual environment?

A virtual environment is a tool that helps to keep dependencies required by different projects separate by creating isolated python virtual environments for them. This is one of the most important tools that most Python developers use.

Why virtual environments?

virtualenv is used to manage Python packages for different projects. Using virtualenv allows you to avoid installing Python packages globally which could break system tools or other projects.

How to create virtual environments?

Here I use the vscode terminal for the creation of a python virtual environment.

If you don’t have vscode you can install it by using the below URL:

After that open your terminal and run the following command:

python3 -m venv hasmukh

In the above command, hasmukh is the name of the virtual environment that you want to create you can write anything here.

If the command run successfully then it’s done, but here you can see that we got an error.

Screenshot Taken By Author

Now first, we have to install python3.8-venv in my case (please use your python version) using this command:

sudo apt install python3.8-venv

Screenshot Taken By Author

After that try to run the bellow command again.

python3 -m venv hasmukh

Screenshot Taken By Author

You can see that it runs successfully.

Type ll in your terminal to see if it’s created or not.

Screenshot Taken By Author

Now we have to activate this environment, so run the bellow command.

source hasmukh/bin/activate

Screenshot Taken By Author

If it’s successfully activated then you can see some changes in your terminal, you can see the virtual environment name on starting of your terminal.

Happy Learning And Keep Learning.

Thank You.

--

--

Hasmukh Mer
Hasmukh Mer

Written by Hasmukh Mer

Machine Learning Engineer || Computer Enthusiastic || Learner || https://www.galaxyofai.com/ ||

No responses yet