flappybird
flappybird

Reputation: 21

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

Upvotes: 0

Views: 1384

Answers (2)

CristiFati
CristiFati

Reputation: 41147

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:

Upvotes: 1

phd
phd

Reputation: 94827

Install virtualenv with Python 2.7:

E:\python27\python.exe -m pip install -U "pip<21.0" "setuptools<45" wheel
E:\python27\python.exe -m pip install -U virtualenv

and use it:

E:\python27\python.exe -m virtualenv venv

PS. Python 2.2 and Python 3 less than 3.4 are too old an unusable. But there is nothing wrong with 2.7 and 3.4+.

Upvotes: 0

Related Questions