Issue
I'm new to programming and i see lots of post saying you have to create a virtual environment for better experience while working on a python project, and i can't really wrap my head on that..... First question, why do I need a virtual environment? Secondly, what happens if i don't use one Also, how do I install it what are the necessary procedures for a beginner Lastly, how do I know I'm using a virtual environment in python, like how do I tell the difference or there is none??
Hoping to get answers
Solution
why do I need a virtual environment?
Because a virtual environment will prevent clashes if you have several applications requiring different versions of Python, or different versions of some Python packages. You might not run into such issues as a beginner, but it's a good habit to have, nevertheless.
what happens if I don't use one?
You might have an application, which is unable to run, because of conflicting requirements.
how do I install it?
Running python3 -m venv my-app
will create the directory my-app
, containing a virtual environment.
After creating a virtual environment, you can activate it with source my-app/bin/activate
on Unix, or macOS, and with my-app/Scripts/activate.bat
on Windows.
how do I know I'm using a virtual environment?
If you're using a virtual environment your prompt will show its name, e.g. (my-app) $
.
See also the section Virtual Environments, and Packages, from The Python Tutorial.
Answered By - Dani Answer Checked By - Willingham (WPSolving Volunteer)