pythonpython-3.xpython-2.7virtualenvvirtual-environment

Creation of Virtual environment with python 3.9 version is executed successfully but python version 2.7 or python version 2.2 shows error


When creating a virtual environment using the 'virtualenv' module, using python 3.11 as deafult/ in the Path, in WINDOWS 10 , I encounter the following weird error. Creation of a virtualenvironment with python 3.9 which is installed in "E:\python33\python.exe" is successful, but creation of virtual environment with python python 2.2 or 2.7 which is also installed in "E:\python27\python.exe" fails. Following are the errors shown in command prompt.

C:\Users\abc\Desktop>virtualenv -p E:\python27\python.exe tl343f
RuntimeError: failed to query E:\python27\python.exe with code 1 err: '  File "C:\\Users\\abc\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages\\virtualenv\\discovery\\py_info.py", line 24\n    return list(OrderedDict.fromkeys(["", *os.environ.get("PATHEXT", "").lower().split(os.pathsep)]))\n                                          ^\nSyntaxError: invalid syntax\n'

C:\Users\abc\Desktop>virtualenv -p E:\python33\python.exe kljkj33
created virtual environment CPython3.9.12.final.0-64 in 738ms
  creator CPython3Windows(dest=C:\Users\abc\Desktop\kljkj33, 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\abc\AppData\Local\pypa\virtualenv)
    added seed packages: pip==23.2.1, setuptools==68.2.0, wheel==0.41.2
  activators BashActivator,BatchActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator

C:\Users\abc\Desktop>

I am expecting the code to execute similar to how it executes when I want to create a virtual environment with python3.9 version. But it fails when creating a virtual environment with python2.7 or python2.2 version


Solution

  • According to [Python]: Sunsetting Python 2 (emphasis is mine):

    We have decided that January 1, 2020, was the day that we sunset Python 2.

    It's no longer supported for more than 3.5 years. I'm not even going to discuss Python 2.2 (as it has been probably dead for more than 10 years).

    [PyPI]: virtualenv only supports Python >= v3.7. Syntax in VirtualEnv files is no longer compatible with Python 2, that's why you get the error.

    So, you should move away from Python 2.7 to a more actual (and decent) version (v3.8 is oldest version currently supported (in security mode)).

    As a workaround, you could install (and use) [PyPI]: virtualenv 20.15.1, which is the newest VirtualEnv version still supporting Python 2.

    Might be related: