英文:
Create virtualenv for python 2.7 with python 3.10
问题
我试图在Ubuntu 22.04上为Python 2.7创建一个虚拟环境。我总是收到以下错误:
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$ 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$
是否有其他人遇到过这个问题或成功解决过?
英文:
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?
答案1
得分: 2
virtualenv
版本 >= 20.22.0 不再支持 创建 Python 环境来适用于 Python 版本 <= 3.6,因此您需要降级 virtualenv
,例如:
pip install virtualenv==20.21.1
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论