Introduction
This article’s content is focusing on the process for creating a python virtual environment. The process for creating a python virtual environment is available in the Microsoft Windows. Before creating a python virtual environment in the device, there are several requirements which is very important. It is very important because without those requirements, it is not possible to do that. So, before creating a python virtual environment, just do several things before.
Create a Python Virtual Environment in Microsoft Windows
There are several things before creating the python virtual environment. So, this part will consists of several parts where each part has different focus. The first part is the preparation part where the purpose is just preparing the environment before creating the python virtual environment. The next part is the actual part for creating the python virtual environment. Last but not least, it is the part for testing the python virtual environment.
Step for Preparing the Requirement
In order to create a python virtual environment, there are several requirements for it. Just prepare the following steps as follow :
-
First of all, install python. Read in the article with the title of ‘How to Install Python in Microsoft Windows’ in this link to get information on installing python in Windows. Also, another article with the title of ‘How to Install pip in Microsoft Windows’ in this link for installing python in Ubuntu.
-
After successfully installing python, install pip. For a reference, just check the article for installing pip in this link. It is an article where the title is ‘How to Install pip in Microsoft Windows’.
-
Before creating the python virtual environment, just install the virtualenv module first. It is a module or a library where it is possible with it to create it. The following is the command for installing virtualenv module using ‘pip’ command :
pip install virtualenv
Step to Create and Test the Python Virtual Environment
In order to create it, just access the command prompt or the command line interface. It is where the process for creating the python virtual environment. Those steps exist as follow :
-
Finally, after installing python and pip, the process for creating a python virtual environment is possible. Just run the command line interface as follows :
C:\programming\python>virtualenv envtest created virtual environment CPython3.8.2.final.0-64 in 13537ms creator CPython3Windows(dest=C:\programming\python\envtest, clear=False, global=False) seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, via=copy, app_data_dir=C:\Users\Personal\AppData\Local\pypa\virtualenv\seed-app-data\v1.0.1) activators BashActivator,BatchActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator C:\programming\python>
-
Last but not least, check whether the python virtual environment exist. Make sure to test it and also to activate it in order to make sure that it is actually working. Just execute the following sequence of command :
First of all, list the existing content :
C:\programming\python>dir Volume in drive C is Windows Volume Serial Number is E003-3593 Directory of C:\programming\python 09/18/2021 08:31 PM <DIR> . 09/18/2021 08:31 PM <DIR> .. 09/18/2021 08:31 PM <DIR> envtest 1 Dir(s) 267,104,256 bytes free C:\programming\python>
Fortunately, the folder with the name of ‘envtest’ exist as the folder where it is actually act as a python virtual environment. Continue on, just get into the folder as follows :
C:\programming\python>cd envtest C:\programming\python\envtest>
Get into another folder which is the ‘Scripts’ folder. In that folder there will be a file with the name of ‘activate’. Execute that file to activate the python virtual environment as follows :
C:\programming\python\envtest>cd Scripts C:\programming\python\envtest\Scripts>activate (envtest) C:\programming\python\envtest\Scripts>
Last step, in order to confirm that the python virtual environment is a new one, just try to execute the following command to list the available modules, packages or libraries :
(envtest) C:\programming\python\envtest\Scripts>pip list Package Version ---------- ------- pip 20.0.2 setuptools 46.1.3 wheel 0.34.2 WARNING: You are using pip version 20.0.2; however, version 21.2.4 is available. You should consider upgrading via the 'C:\programming\python\envtest\Scripts\python.exe -m pip install --upgrade pip' command. (envtest) C:\programming\python\envtest\Scripts>