Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Create virtualenv for python 2.7 with python 3.10

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading