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

问题描述 投票:0回答:3

我刚刚升级到 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']

接下来我使用了

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

如果我使用的话也会遇到类似的情况

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'

我的 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/[email protected]) 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/[email protected]) 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

我还已经添加了 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后
  3. python3.8-venv不再工作
  4. 在 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已经改变了

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

python python-3.x ubuntu virtualenv
3个回答
1
投票

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

您可以创建您的环境

pyenv virtualenv 3.10.0 my_env

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

pyenv activate my_env

1
投票

我在

python3.10-venv
 上安装 
Ubuntu22.04.1 LTS

时遇到了同样的问题

但是,只需升级 apt 即可解决该问题。

sudo apt update
sudo apt upgrade

事后

sudo apt install python3.10-venv
工作顺利。

编辑:(关于更新问题)
抱歉,我确实注意到您的问题

apt update

您看过
/etc/apt/sources.list
文件吗?
该警告表明文件中存在重复行。 如果是这样,也许尝试删除重复项?

但是,这不应该成为问题。 所以,如果您还没有尝试过,请尝试

sudo apt upgrade


0
投票

从另一个问题的评论中发现问题是因为我写问题时尚未添加 venv 包

运行

sudo apt install python3.10-venv

 现在允许我安装该软件包,并且我现在可以在默认的 Ubuntu 22.04 LTS 上创建一个 python3.10 虚拟环境

© www.soinside.com 2019 - 2024. All rights reserved.