Introduction
This is another article where the main focus is about how to create a python virtual environment. But there is one different part from the other article where it also focusing on how to create that python virtual environment. Actually, there is a specific command for creating the python virtual environment. Normally, that command will just need another parameter which is the name of the python virtual environment. But in this article, there is one additional parameter which is useful for further execution with that command. That additional parameter has a specific purpose for defining the python version. Specifically, it will be the base python version for further usage in the python virtual environment as soon as it is active and running.
How to Create Python Virtual Environment with specific Python version
In general, the step is quite simple, but it really need to pass the correct path location of the python version. Below is the step for creating the python virtual environment with a specific version of the existing python :
-
First of all, just run the Command Prompt. In order to ensure the execution process, just use the Administrator account or any account which has an Administrator previlege. Just to make sure that the execution process will proceed without any further error. Especially, occurring errors which has something to do with the lack of privileges.
-
In the Command Prompt, just execute the following command :
C:\repository\django\project>virtualenv --python "C:\Users\Personal User\AppData\Local\Programs\Python\Python310\python.exe" virtualenv created virtual environment CPython3.10.5.final.0-64 in 2673ms creator CPython3Windows(dest=C:\temp\virtualenv, clear=False, no_vcs_ignore=False, global=False) seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=C:\Users\Personal User\AppData\Local\pypa\virtualenv) added seed packages: pip==22.1.2, setuptools==62.3.4, wheel==0.37.1 activators BashActivator,BatchActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator C:\repository\django\project>
-
Next step, just get into the folder of the newly created python virtual environment as follows :
C:\repository\django\project>cd virtualenv C:\repository\django\project\virtualenv>dir Volume in drive C is Windows-SSD Volume Serial Number is CA30-19A4 Directory of C:\repository\django\project\virtualenv 06/24/2022 02:34 PM <DIR> . 06/24/2022 02:34 PM <DIR> .. 06/24/2022 02:34 PM 42 .gitignore 06/24/2022 02:34 PM <DIR> Lib 06/24/2022 02:34 PM 434 pyvenv.cfg 06/24/2022 02:34 PM <DIR> Scripts 2 File(s) 476 bytes 4 Dir(s) 137,482,539,008 bytes free C:\repository\django\project\virtualenv>
-
Last but not least, just try to activate the python virtual environment by typing the ‘activate’ to run the ‘activate.bat’ file exist in the ‘Scripts’ directory as follows :
C:\repository\django\project\virtualenv>cd Scripts C:\repository\django\project\virtualenv\Scripts>dir Volume in drive C is Windows-SSD Volume Serial Number is CA30-19A4 Directory of C:\repository\django\project\virtualenv\Scripts 06/24/2022 02:34 PM <DIR> . 06/24/2022 02:34 PM <DIR> .. 06/24/2022 02:34 PM 2,141 activate 06/24/2022 02:34 PM 981 activate.bat 06/24/2022 02:34 PM 3,018 activate.fish 06/24/2022 02:34 PM 2,555 activate.nu 06/24/2022 02:34 PM 1,758 activate.ps1 06/24/2022 02:34 PM 1,193 activate_this.py 06/24/2022 02:34 PM 510 deactivate.bat 06/24/2022 02:34 PM 682 deactivate.nu 06/24/2022 02:34 PM 106,860 pip-3.10.exe 06/24/2022 02:34 PM 106,860 pip.exe 06/24/2022 02:34 PM 106,860 pip3.10.exe 06/24/2022 02:34 PM 106,860 pip3.exe 06/24/2022 02:34 PM 24 pydoc.bat 06/24/2022 02:34 PM 264,176 python.exe 06/24/2022 02:34 PM 252,912 pythonw.exe 06/24/2022 02:34 PM 106,847 wheel-3.10.exe 06/24/2022 02:34 PM 106,847 wheel.exe 06/24/2022 02:34 PM 106,847 wheel3.10.exe 06/24/2022 02:34 PM 106,847 wheel3.exe 19 File(s) 1,384,778 bytes 2 Dir(s) 135,783,374,848 bytes free C:\temp\virtualenv\Scripts> C:\repository\django\project\virtualenv\Scripts>activate (virtualenv) C:\repository\django\project\virtualenv\Scripts> (virtualenv) C:\repository\django\project\virtualenv\Scripts>python.exe -V Python 3.10.5 (virtualenv) C:\repository\django\project\virtualenv\Scripts>
As it exist in the above command execution, it finally success to activate the python virtual environment. It also display the version of the python exist as the base of