Set up your Virtual Environment (Python)
Why do we need virtualenv?
Virtual environment separate packages, python versions and libraries we install in our local computer. Probably, the best example that I can think is to separate versions and dependencies of each your project you have. You do not like to use python3 in your previous projects which was created in python2. It might have conflicts or worst it might crash your application and the packages you installed in your old project.
For further details about virtualenv. You may check the link below.
Now let’s set up a virtualenv.
Go to your desired directory where you want to install virtualenv
In my case, I’d like to put my virtualenv in Documents/Dev directory
Install: Enter the command pip install virtualenv
Once you’ve installed it successfully. You may now create a virtualenv by entering (virtualenv my_virtual_env) and try to display the item in your directory. Enter the command ls -lrt
How to activate the created virtualenv that you’ve created.
If you are using Windows OS, you have to activate the virtualenv by entering:
my_virtual_env\scripts\activate
On Mac OS:
source my_virtual_env/bin/activate
In my case…
Now that we are inside the virtualenv which is my_virtual_env in my case. Let’s check what applications we have inside it.
To check, enter this command pip list
Make sure to activate the virtualenv you want before you install different packages inside it.
I hope that you’ve learned a lot. Thank you.