Quick post today, and mostly a reminder on how to create a Virtual Environment in Python in Windows 10. I’ve been doing this mostly in my Mac and my Raspberry Pi, and I always forget how to do this on Windows, so … I’ll write this post to have this
Download the installers from the official Python source (see references). I usually install it on the root of my C: hard drive and name it with the version. In example: c:\Python37_64 folder.
Remember to also add this folder and the Scripts folder to the Environment Variables.
Note: Once you start to install tools which uses Python, your OS becomes a nightmare. You will have your own installed python, the version installed with Visual Studio, the one with Visual Studio Code, another one for Anaconda.
I’m not sure if this is a best practice or not, but I usually remove all the other versions and keep mines in the root of the C: drive.
Ok, let’s go on.
For a new virtual environment named “testEnv”, open a command prompt and navigate to the python folder. Then run the command
python -m virtualenv testEnv
After a couple of seconds, the virtual Environment will be installed, and you can use it by run the [activate.bat] script. In this example
- The virtual environment will be created at [c:\Python37_64\testEnv]
- The virtual environment activate script will be at [c:\Python37_64\testEnv\Scripts\activate.bat]
So the full command sequence is similar to this one
Now you have your virtual environment up and running and you may want to start to add your own packages or tools. Like in example: Numpy or to list the installed packages
Finally, you may leave the virtual environment with the command
Greetings @ Toronto