Issue
I am trying to create a virtual environment for python 2.7 on Ubuntu 22.04. I always receive an error as follows:
RuntimeError: failed to query /usr/bin/python2.7 with code 1 err: ' File "/usr/local/lib/python3.10/dist-packages/virtualenv/discovery/py_info.py", line 152\n os.path.join(base_dir, exe) for exe in (f"python{major}", f"python{major}.{minor}")\n ^\nSyntaxError: invalid syntax\n'
Here is a capture of my terminal for useful information:
user@machine:~/environments$ ls /usr/bin/pytho*
/usr/bin/python2 /usr/bin/python2.7 /usr/bin/python3 /usr/bin/python3-config /usr/bin/python3.10 /usr/bin/python3.10-config
user@machine:~/environments$ pip --version
pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.10)
user@machine:~/environments$ virtualenv --version
virtualenv 20.23.0 from /usr/local/lib/python3.10/dist-packages/virtualenv/__init__.py
user@machine:~/environments$ virtualenv -p /usr/bin/python2.7 py2_env
RuntimeError: failed to query /usr/bin/python2.7 with code 1 err: ' File "/usr/local/lib/python3.10/dist-packages/virtualenv/discovery/py_info.py", line 152\n os.path.join(base_dir, exe) for exe in (f"python{major}", f"python{major}.{minor}")\n ^\nSyntaxError: invalid syntax\n'
user@machine:~/environments$
Has anyone else had this problem, or successfully achieved this?
Solution
virtualenv
versions >= 20.22.0 dropped support for creating Python environments for Python versions <= 3.6, so you'll need to downgrade virtualenv
, e.g.:
pip install virtualenv==20.21.1
Answered By - Matt Pitkin Answer Checked By - Cary Denson (WPSolving Admin)