我刚刚升级到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更新也看起来很可疑,但我不完全确定它是否是罪魁祸首
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
我也已经将deadsnakes添加到repos中。我注意到其他一些问题是针对python 3.6或3.8的,当我分别使用python 3.6和3.8时,它们在过去已经工作了。但是,其中描述的方法不适用于我目前使用Ubuntu 22.04和python3.10的设置。
- python3.8-venv不支持python3.8 -m venv env
- python3.8-venv在Pop OS升级到21.04后不再工作
- 在Ubuntu 22.04上安装Python3.6虚拟环境出现问题
这些是我咨询过但不适合我的其他链接。我也试过重新安装python3.10。
- 如何在Ubuntu上使用Python3.10 ?
- 在Ubuntu 22.04上安装Python3.6虚拟环境出现问题
- pyvenv不工作,因为ensurepip不可用
- pyvenv不工作,因为ensurepip不可用
- https://askubuntu.com/questions/879437/ensurepip-is-disabled-in-debian-ubuntu-for-the-system-python
- Python3.10 source venv已更改
问:当python3.10-venv没有安装候选时,如何安装python3.10虚拟环境?
python3.10-venv通常是提供用于在Python 3.10中创建虚拟环境的venv模块的包。如果在您尝试安装它时没有找到该包,这可能意味着它在您的特定发行版或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
这将创建一个使用Python 3.10.0的名为my_env的新虚拟环境。激活虚拟环境,执行如下命令:
pyenv activate my_env
我在Ubuntu22.04.1 LTS
上安装python3.10-venv
时遇到了同样的问题
但是,这个问题通过升级apt就解决了。
sudo apt install update
sudo apt install upgrade
之后,sudo apt install python3.10-venv
工作顺利。
编辑:(关于更新的问题)
对不起,我注意到你的apt update
的问题。
你看过/etc/apt/sources.list
文件了吗?
警告提示文件中有重复的行。如果是这样,也许可以尝试删除重复的内容?
然而,这应该不是一个问题。所以,如果你还没有,请尝试sudo apt upgrade
。
从另一个问题的注释中发现问题是由于在我写这个问题时还没有添加venv包
运行sudo apt install python3.10-venv
现在允许我安装包,我现在可以在默认的Ubuntu 22.04 LTS上创建一个python3.10虚拟环境