Virtualenv无法找到新安装的Python版本

5
我正在运行Ubuntu 20.04,想要使用Python 3.10开展项目。我参考了一个Python 3.10安装指南(这个),使用deadsnakes PPA进行了安装,一切顺利:
$ python3.10
Python 3.10.5 (main, Jun 11 2022, 16:53:24) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

为了保险起见,我甚至将我的默认 Python 版本切换到 3.10,使用这个方法,也可以正常工作。

$ python
Python 3.10.5 (main, Jun 11 2022, 16:53:24) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

然而我无法构建虚拟环境:

$ virtualenv myenv -p python3.10         
RuntimeError: failed to find interpreter for Builtin discover of python_spec='python3.10'

如果我试图依赖默认设置,它会给我安装python3.8版本。我之前一直在使用python3.8,但我不知道这个设置从哪里来。安装了Pyenv,我不知道它是否干扰了这个设置。

$ virtualenv myenv                                                                                                
created virtual environment CPython3.8.10.final.0-64 in 110ms
  creator CPython3Posix(dest=/home/jokea/FlorA/fl-scraper/myenv, clear=False, global=False)
  seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, pkg_resources=latest, via=copy, app_data_dir=/home/jokea/.local/share/virtualenv/seed-app-data/v1.0.1.debian.1)
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator

我想使用Python3.10创建一个虚拟环境,可能会有什么遗漏吗?

2个回答

7

我在安装全新的 Python 3.7 时遇到了同样的问题。通过安装 distutils ,我成功解决了它。

sudo apt-get install python3.7-distutils 

你的回答可以通过提供更多支持信息来改进。请编辑以添加进一步的细节,例如引用或文档,以便他人可以确认你的答案是正确的。您可以在帮助中心中找到有关如何编写良好答案的更多信息。 - Community
1
就是这样了。向你致敬,先生。 - John Kealy

1

创建虚拟环境时,您可以尝试输入Python3.10的完整路径,例如:

virtualenv --python=/usr/bin/python3.10 venv

我尝试了一下,但是出现了这个奇怪的错误: “RuntimeError: failed to query /usr/bin/python3.10 with code 1 err: '/usr/lib/python3/dist-packages/virtualenv/discovery/py_info.py:16: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential...” - John Kealy
是的,我遇到了同样的错误。有没有更新? - Yuri R

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接