When most people try Python for the first time they don’t think about the way they are downloading it.
They likely figured that the Python website would tell them how to download python properly, but it doesn’t.
This guide might not be for the person who just picked up Python using the default libraries, but anyone that works with Python in projects should consider reading this guide.

Python Virtual Environments allows the modules and libraries of each project to stay separate to be used for only that specific project.
This means that if two separate projects use certain libraries that might not work together it won’t break everything.
Ex. one project could be using Tensorflow as the Machine Learning framework and another project could be using Scikit-Learn, which wouldn’t be ideal.

In this guide, I will show you how to set up a Python Virtual Environment as you are downloading Python for the first time.

Step 1 (Get PC ready for Python venv):

First, you need to have folders for your virtual environment and more importantly your python installation.

Open the Command Prompt and type “mkdir pyver” and hit enter.
Then type “mkdir pyproj” and hit enter.

Step 2 (Install Python):

When you have created the two folders, you can now install Python.
Simply go to the Python website and download the newest version you can find.
Then open the installer and select “Customize installation”.
Then keep the Advanced Options as they are, but change the install location to the “pyver” folder under your user.
Then write a new folder in the “Customize install location” with the name of the python version you downloaded.
Then press the Install button.

Step 3 (Set up environment):

Now that you have python, you can start creating a virtual environment.
Open the command prompt again and type “cd pyproj”.
Then type this long command: “c:\Users\yourname\pyver\yourpythonversion\python -m venv my_env” and hit enter.
(The “yourname” is your windows username and “yourpythonversion” is the folder you downloaded Python to, which in my case was called “py397”).

Step 4 (Using your new venv):

Now you have installed and created a virtual environment now you just have to activate it.
You need the open the command prompt again for this step.
Type “cd pyproj”, if you aren’t already in that folder.
Then type “my_env\Scripts\activate” and hit enter.
Then you will get “(my_env)” in front of your command line and that means that you are inside the environment.
Now you can download all the modules and libraries that you want, and when you are done simply write “deactivate” in the command prompt and the environment will close.

Step 5 (Adding to IDE):

Now you have your virtual environment and you have downloaded all of your modules and libraries, now you can use it in your favorite IDE.
Simply go open up your new project in the “pyproj” folder with your IDE and start coding.
I have a little post-it note with the activate and deactivate commands so I can remember them, and I would encourage you to also make a little note like so: