python3.10-venv没有安装候选时如何安装python3.10虚拟环境?

fat*_*ger 6 python ubuntu virtualenv python-3.x

我刚刚升级到 Ubuntu 22.04.1 LTS,它预装了 python3.10。我尝试创建虚拟环境但不成功。尝试安装虚拟环境包出现错误E: Package 'python3-venv' has no installation candidate

python3 -m venv newpy310
The virtual environment was not created successfully because ensurepip is not
available.  On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.

    apt install python3.10-venv

You may need to use sudo with that command.  After installing the python3-venv
package, recreate your virtual environment.

Failing command: ['/home/user/Desktop/pyenvs/newpy310/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']
Run Code Online (Sandbox Code Playgroud)

接下来我使用了sudo apt install python3.10-venv,并返回了

sudo apt install python3.10-venv
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package python3.10-venv is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'python3.10-venv' has no installation candidate
Run Code Online (Sandbox Code Playgroud)

如果我使用的话也会遇到类似的情况sudo apt install python3.10-virtualenv

sudo apt-get install python3.10-virtualenv
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package python3.10-virtualenv
E: Couldn't find any package by glob 'python3.10-virtualenv'
E: Couldn't find any package by regex 'python3.10-virtualenv'
Run Code Online (Sandbox Code Playgroud)

我的 sudo apt-get update 看起来也很可疑,但我不完全确定它是否是罪魁祸首

sudo apt update
Hit:1 http://archive.ubuntu.com/ubuntu focal InRelease                                                 
Hit:2 http://security.ubuntu.com/ubuntu jammy-security InRelease                                       
Hit:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease                                         
Hit:4 http://archive.ubuntu.com/ubuntu focal-security InRelease                  
Hit:5 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu jammy InRelease
Hit:6 http://archive.ubuntu.com/ubuntu focal-backports InRelease
Hit:7 http://archive.ubuntu.com/ubuntu jammy InRelease
Hit:8 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
8 packages can be upgraded. Run 'apt list --upgradable' to see them.
W: Target Packages (main/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target Packages (main/binary-i386/Packages) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target Packages (main/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target Translations (main/i18n/Translation-en_US) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target Translations (main/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target Translations (main/i18n/Translation-en_SG) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target DEP-11 (main/dep11/Components-amd64.yml) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target DEP-11 (main/dep11/Components-all.yml) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target DEP-11-icons-small (main/dep11/icons-48x48.tar) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target DEP-11-icons (main/dep11/icons-64x64.tar) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target DEP-11-icons-hidpi (main/dep11/icons-64x64@2.tar) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target CNF (main/cnf/Commands-amd64) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target CNF (main/cnf/Commands-all) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target Packages (main/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target Packages (main/binary-i386/Packages) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target Packages (main/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target Translations (main/i18n/Translation-en_US) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target Translations (main/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target Translations (main/i18n/Translation-en_SG) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target DEP-11 (main/dep11/Components-amd64.yml) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target DEP-11 (main/dep11/Components-all.yml) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target DEP-11-icons-small (main/dep11/icons-48x48.tar) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target DEP-11-icons (main/dep11/icons-64x64.tar) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target DEP-11-icons-hidpi (main/dep11/icons-64x64@2.tar) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target CNF (main/cnf/Commands-amd64) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target CNF (main/cnf/Commands-all) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
Run Code Online (Sandbox Code Playgroud)

我还已经添加了 deadsnakes ppa 存储库。我注意到其他一些问题是针对 python 3.6 或 3.8 的,这些问题在我过去分别使用 python 3.6 和 3.8 时有效。但是,其中描述的方法不适用于我当前使用 Ubuntu 22.04 和 python3.10 的设置。

  1. python3.8-venv 不与 python3.8 -m venv env 一起使用
  2. Pop OS 升级到 21.04 后 python3.8-venv 不再工作
  3. 在Ubuntu 22.04上安装Python3.6虚拟环境时遇到问题

这些是我咨询过但对我不起作用的其他链接。我也尝试过重新安装 python3.10 本身。

  1. 如何在Ubuntu上使用Python3.10?
  2. 在Ubuntu 22.04上安装Python3.6虚拟环境时遇到问题
  3. pyvenv 无法工作,因为 Ensurepip 不可用
  4. pyvenv 无法工作,因为 Ensurepip 不可用
  5. https://askubuntu.com/questions/879437/ensurepip-is-disabled-in-debian-ubuntu-for-the-system-python
  6. Python3.10源码venv已经改变

Q:当python3.10-venv没有安装候选时,如何安装python3.10虚拟环境?

Ser*_*nes 0

python3.10-venv 通常是提供 venv 模块的包,用于在 Python 3.10 中创建虚拟环境。如果您尝试安装时找不到该软件包,则可能意味着该软件包在您的特定发行版或 Linux 版本的软件包存储库中不可用。

使用 Python 3.10 创建虚拟环境的一种方法是使用 pyenv 工具。pyenv 允许您轻松地在系统上安装和管理多个版本的 Python。您可以按照 GitHub 页面上的说明安装 pyenv: https: //github.com/pyenv/pyenv

安装 pyenv 后,您可以通过运行以下命令来安装 Python 3.10:

pyenv install 3.10.0
Run Code Online (Sandbox Code Playgroud)

您可以创建您的环境

pyenv virtualenv 3.10.0 my_env

Run Code Online (Sandbox Code Playgroud)

这将创建一个名为 my_env 的新虚拟环境,该环境使用 Python 3.10.0。要激活虚拟环境,请运行以下命令:

pyenv activate my_env
Run Code Online (Sandbox Code Playgroud)