Introduction
Actually, this article is going to show step for choosing specific python version. It is useful to create a python virtual environment. The process for creating the python virtual environment is in a local device. That local device is running using Microsoft Windows as its operating system. There is a requirement for creating the virtual python environment by defining the python version. In this case, executing the command directly without having a specific python version definition. Sometime, it will not get the right python version as its base. Furthermore, if that python version is the actual cause for the failure of several command execution. Below is the exact description for the previous statement :
C:\repository\docker\django\myproject>python -V Python 3.10.5 C:\repository\docker\django\myproject>
Globally, the version of the currently running and active python in the environment variable is python with version of ‘3.10.5’. But at the time in the process for creating a python virtual environment, the python version used as the base python is totally different. That condition appear in the following sequence of command execution :
C:\repository\docker\django\myproject>virtualenv env virtualenv env created virtual environment CPython3.9.10.final.0-64 in 6620ms creator CPython3Windows(dest=C:\repository\docker\django\myproject, 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\docker\django\myproject>cd env C:\repository\docker\django\myproject\env>dir Volume in drive C is Windows-SSD Volume Serial Number is CA30-19A4 Directory of C:\repository\docker\django\myproject\env 06/14/2022 09:19 PM. 06/14/2022 09:19 PM.. 06/14/2022 09:19 PM 42 .gitignore 06/14/2022 09:19 PM bin 06/14/2022 09:19 PM lib 06/14/2022 09:19 PM 298 pyvenv.cfg 2 File(s) 340 bytes 4 Dir(s) 142,856,839,168 bytes free C:\repository\docker\django\myproject\env>dir C:\repository\docker\django\myproject\env>cd bin C:\repository\docker\django\myproject\env\bin>dir Volume in drive C is Windows-SSD Volume Serial Number is CA30-19A4 Directory of C:\repository\docker\django\myproject\env\bin 06/14/2022 09:19 PM <DIR> . 06/14/2022 09:19 PM <DIR> .. 06/14/2022 09:19 PM 2,135 activate 06/14/2022 09:19 PM 975 activate.bat 06/14/2022 09:19 PM 3,012 activate.fish 06/14/2022 09:19 PM 2,543 activate.nu 06/14/2022 09:19 PM 1,754 activate.ps1 06/14/2022 09:19 PM 1,199 activate_this.py 06/14/2022 09:19 PM 510 deactivate.bat 06/14/2022 09:19 PM 682 deactivate.nu 06/14/2022 09:19 PM 106,854 pip-3.9.exe 06/14/2022 09:19 PM 106,854 pip.exe 06/14/2022 09:19 PM 106,854 pip3.9.exe 06/14/2022 09:19 PM 106,854 pip3.exe 06/14/2022 09:19 PM 24 pydoc.bat 06/14/2022 09:19 PM 99,446 python.exe 06/14/2022 09:19 PM 97,910 pythonw.exe 06/14/2022 09:19 PM 106,841 wheel-3.9.exe 06/14/2022 09:19 PM 106,841 wheel.exe 06/14/2022 09:19 PM 106,841 wheel3.9.exe 06/14/2022 09:19 PM 106,841 wheel3.exe 19 File(s) 1,064,970 bytes 2 Dir(s) 142,854,467,584 bytes free C:\repository\docker\django\myproject\env\bin>activate (env) C:\repository\docker\django\myproject\env\bin>python -V Python 3.9.10 (env) C:\repository\docker\django\myproject\env\bin>
The above python version is not the default one which is currently running and active. The same condition also appear in several previous articles. Because it is using a different version of python, it trigger error messages. For an example, it exist in an article with the title of ‘How to Solve Error Message python setup.py egg_info did not run successfully distutils.errors.DistutilsPlatformError: –plat-name must be one of (‘win32’, ‘win-amd64’, ‘win-arm32’, ‘win-arm64’) when running pip install -r requirements.txt in Microsoft Windows’ in this link.
Another one is article with the title of ‘How to Solve Error Message python setup.py egg_info did not run successfully ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129) when running pip install -r requirements.txt in Microsoft Windows’ in this link. Those error appear because of the incorrect python version for creating a python virtual environment.
How to Specify Specific Python Version for Creating Python Virtual Environment in Microsoft Windows
This part will show the step to create virtual python environment. Below, the steps exist in sequence :
-
So, the first step to achieve the purpose is to execute the Command Prompt.
-
Check the availability of the python in the local device which is running Microsoft Windows as in the next step below :
C:\>where python C:\Users\Personal User\AppData\Local\Programs\Python\Python310\python.exe C:\Program Files\Inkscape\bin\python.exe C:\Users\Personal User\AppData\Local\Microsoft\WindowsApps\python.exe C:\>
-
As in the list above, the version of the default python which exist in the top of the list is the ‘3.10.xx’. But in the introduction part, the version is ‘3.9.10’. So, it does not use the correct version of the python for the base of the python virtual environment. In that case, just execute the following command :
C:\repository\docker\django\myproject>virtualenv --python "C:\Users\Personal User\AppData\Local\Programs\Python\Python310\python.exe" virtualenv created virtual environment CPython3.10.5.final.0-64 in 1257ms creator CPython3Windows(dest=C:\repository\docker\django\dandes\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.0.4, setuptools==62.1.0, wheel==0.37.1 activators BashActivator,BatchActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator C:\repository\docker\django\myproject> cd virtualenv
- Following after, do not forget to check inside the folder of the new python virtual environment as follows :
C:\repository\docker\django\myproject\virtualenv>dir Volume in drive C is Windows-SSD Volume Serial Number is CA30-19A4 Directory of C:\repository\docker\django\myproject\virtualenv 06/14/2022 08:16 PM <DIR> . 06/14/2022 08:16 PM <DIR> .. 06/14/2022 08:16 PM 42 .gitignore 06/14/2022 08:16 PM Include 06/14/2022 08:16 PM Lib 06/14/2022 08:16 PM 434 pyvenv.cfg 06/14/2022 08:16 PM Scripts 2 File(s) 476 bytes 5 Dir(s) 142,900,842,496 bytes free C:\repository\docker\django\myproject\virtualenv>cd Scripts C:\repository\docker\django\myproject\virtualenv\Scripts>dir Volume in drive C is Windows-SSD Volume Serial Number is CA30-19A4 Directory of C:\repository\docker\django\myproject\virtualenv\Scripts 06/14/2022 08:16 PM <DIR> . 06/14/2022 08:16 PM <DIR> .. 06/14/2022 08:16 PM 2,136 activate 06/14/2022 08:16 PM 976 activate.bat 06/14/2022 08:16 PM 3,013 activate.fish 06/14/2022 08:16 PM 2,545 activate.nu 06/14/2022 08:16 PM 1,758 activate.ps1 06/14/2022 08:16 PM 1,193 activate_this.py 06/14/2022 08:16 PM 510 deactivate.bat 06/14/2022 08:16 PM 682 deactivate.nu 06/14/2022 08:16 PM 106,855 pip-3.10.exe 06/14/2022 08:16 PM 106,855 pip.exe 06/14/2022 08:16 PM 106,855 pip3.10.exe 06/14/2022 08:16 PM 106,855 pip3.exe 06/14/2022 08:16 PM 24 pydoc.bat 06/14/2022 08:16 PM 264,176 python.exe 06/14/2022 08:16 PM 252,912 pythonw.exe 06/14/2022 08:16 PM 106,842 wheel-3.10.exe 06/14/2022 08:16 PM 106,842 wheel.exe 06/14/2022 08:16 PM 106,842 wheel3.10.exe 06/14/2022 08:16 PM 106,842 wheel3.exe 19 File(s) 1,384,713 bytes 2 Dir(s) 142,900,944,896 bytes free C:\repository\docker\django\myproject\virtualenv\Scripts>
-
Try to activate the python virtual environment by typing the following command :
C:\repository\docker\django\myproject\virtualenv\Scripts>activate (myenv) C:\repository\docker\django\myproject\virtualenv\Scripts>
-
Last but not least, check the python version exist in that python virtual environment as follows :
(myenv) C:\repository\docker\django\myproject\virtualenv\Scripts>python.exe -V Python 3.10.5 (myenv) C:\repository\docker\django\myproject\virtualenv\Scripts>
So, the version is already using a different one. In the previous one, it is using 3.9.10 where in the new one it has the versioni of ‘3.10.5’.