How To Create And Use Python Virtual Environments
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.
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
After that try to run the bellow command again.
python3 -m venv hasmukh
You can see that it runs successfully.
Type ll in your terminal to see if it’s created or not.
Now we have to activate this environment, so run the bellow command.
source hasmukh/bin/activate
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.