创建用于 Python 2.7 的虚拟环境,并使用 Python 3.10。

huangapple go评论68阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年6月1日 17:16:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76380381.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定