How to Create a Python Virtual Environment in Microsoft Windows

Posted on

Introduction

This article will show to create a python virtual environment in Microsoft Windows operating system. But before creating one of it, there will be a requirement to achieve it. In the opeerating system, there must a python installation first. Furthermore, in the command line, the execution of the python binary file is possible.It is because the definition of the python binary executable in the operating system’s environment variables. First of all, just test whether the python binary executable is available for the execution in the command prompt. Just type the following command in the Command Prompt :

python

The following is the execution of the above command :

Microsoft Windows [Version 10.0.18362.720]
(c) 2019 Microsoft Corporation. All rights reserved.
C:\Users\Personal>python
Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

According to the above output of the command execution, the python binary executable exist and it is available for further execution. Another proper way to get the information without having to redirect the command to the python command console will be executing the following command :

Microsoft Windows [Version 10.0.18362.720]
(c) 2019 Microsoft Corporation. All rights reserved.
C:\Users\Personal>python -V
Python 3.8.2
C:\Users\Personal>

The above command have an additional parameter using -V. Actually, it is just an additional paramaeter for showing the version of the current execution of the python binary version. And according to the output of the above command execution, it is clearly that the python version is ‘3.8.2’.

 

Creating a new Python Virtual Environment

So, after make sure that the python exist and it is available to process any other further instructions, just execute the following command :

python -m venv folder_name_of_the_virtual_environment

Below is the sample of the above command execution :

C:\python-win>python -m venv privenv
C:\python-win>

The above command has an additional parameter after ‘python’. Using -m to pass the module argument after which is ‘venv’ will have an intention to run the ‘venv’ module as a script. It will create a virtual environment with the name of ‘privenv’. As the above command execution is a success, there will be a new folder with the name of ‘privenv’. It will contains lot of different files that will enable the activation of the virtual environment. The following is the content of the folder :

Microsoft Windows [Version 10.0.18362.720]
(c) 2019 Microsoft Corporation. All rights reserved.
C:\Users\Personal>cd \
C:\>cd python-win
C:\python-win>cd privenv
C:\python-win\privenv>dir
Volume in drive C is Windows
Volume Serial Number is E003-3593
Directory of C:\python-win\privenv
04/13/2020 11:55 PM <DIR> .
04/13/2020 11:55 PM <DIR> ..
04/13/2020 11:15 PM <DIR> Include
04/13/2020 11:15 PM <DIR> Lib
04/13/2020 11:15 PM <DIR> Scripts
0 File(s) 0 bytes
5 Dir(s) 237,892,382,720 bytes free
C:\python-win\privenv>

Leave a Reply