Introduction
This article will focus on showing how to activate python virtual environment in Microsoft Windows. Actually, there is another previous article which is also discussing about the similar content. That article is an article with the title of ‘How to Activate Python Virtual Environment’. It exist in this link. The main differentiation between each article is the environment of both of the article. The previous article is activating python virtual environment in Ubuntu. This article will focus on how to activate python virtual environment in Microsoft Windows.
Activate Python Virtual Environment in Microsoft Windows
So, how is the way to activate a python virtual environment in Microsoft Windows ?. Basically, it is easy. Because it is only executing or running one file. Moreover, that file is actually exist in the folder of the virtual environment. The following steps are actually the step for activating the python virtual environment :
-
First of all, off course the existence of python itself. Read the article with the title of ‘How to Install Python in Microsoft Windows’ in this link.
-
Next, the existence of the python virtual environment for further activation. The existence of it depends on the availability of the ‘virtualenv’ module, package or library. In order to install it, just use ‘pip’. Read the article with the title of ‘pip’ installation in this link. It is an article with the title of ‘How to Install pip in Microsoft Windows’. After installing ‘pip’, use ‘pip’ tool itself to install the ‘virtualenv’ module, package or library.
-
Finally, get the ‘virtualenv’ command to create a python virtual environment. Read an article with the title of ‘How to Create a Python Virtual Environment in Microsoft Windows’ in this link for a reference. For an example, the following is the execution for creating a python virtual environment :
C:\programming\python>virtualenv env created virtual environment CPython3.8.2.final.0-64 in 13537ms creator CPython3Windows(dest=C:\programming\python\env, 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>
-
After the process for creating the python virtual environment, just activate it. Just get into the directory or folder of python virtual environment. After that, just get into the Scripts folder. Check whether there is a file with the name of ‘activate.bat’ for Microsoft Windows operating system. Else, a file with the name of ‘activate.sh’ for Linux operating system. Do it as follows :
C:\programming\python>cd env C:\programming\python\env>cd Scripts C:\programming\python\env\Scripts>dir Volume in drive C is Windows Volume Serial Number is E003-3593 Directory of C:\programming\python\env\Scripts 09/20/2021 10:30 PM <DIR> . 09/20/2021 10:30 PM <DIR> .. 09/04/2021 05:38 PM 2,312 activate 09/04/2021 05:38 PM 990 activate.bat 09/04/2021 05:38 PM 18,093 Activate.ps1 09/20/2021 10:29 PM 106,378 cmark.exe 09/04/2021 05:38 PM 368 deactivate.bat 09/04/2021 05:42 PM 103,357 django-admin.exe 09/04/2021 05:42 PM 711 django-admin.py 09/04/2021 05:38 PM 103,324 easy_install-3.8.exe 09/04/2021 05:38 PM 103,324 easy_install.exe 09/20/2021 10:29 PM 106,407 normalizer.exe 09/09/2021 08:41 PM 106,387 pip.exe 09/09/2021 08:41 PM 106,387 pip3.8.exe 09/09/2021 08:41 PM 106,387 pip3.exe 09/20/2021 10:30 PM 106,381 pip_search.exe 09/20/2021 10:29 PM 106,378 pygmentize.exe 09/04/2021 05:38 PM 524,872 python.exe 09/04/2021 05:38 PM 523,848 pythonw.exe 09/04/2021 05:41 PM 103,310 sqlformat.exe 09/04/2021 05:42 PM <DIR> __pycache__ 18 File(s) 2,229,214 bytes 3 Dir(s) 184,680,448 bytes free C:\programming\python\env\Scripts>
Since in this context, the environment is a device running using Microsoft Windows operating system, just execute the ‘activate.bat’ file as follows :
(env) C:\programming\python\env\Scripts> C:\programming\python\env\Scripts>activate (env)