我的系统信息
- 从U盘运行Ubuntu Desktop(22.04.1 LTS(
- 基本机器Windows 11
- Ubuntu上的Python版本为3.10.4
试图创建一个python虚拟环境
python3 -m venv .
获取错误
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: ['/media/ubuntu/New Volume/myWorks/Ubuntu/DALLE_Project/vnv/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']
运行上述命令时
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-venv
也出现了同样的错误。
有什么解决问题的建议吗?
当我在我的系统(Ubuntu 22.04(上遇到这个问题时,我也进行了广泛的搜索,但没有一个建议的解决方案对我有效,包括:
- 预先运行
sudo apt update
和sudo apt upgrade
- 以任何形式使用
pip
(与您的错误相同( - 导出和重新配置区域设置
在我的案例中,解决方案是(重新(启用Ubuntu universe存储库,以便能够安装python3-venv
和相关软件包,因为这在我的机器上被禁用了。
在Ubuntu中,这可以通过运行Software & Updates
工具来完成,该工具也可以通过运行来打开
software-properties-gtk
在终端中,然后确保选中Community-maintained free and open-source software (universe)
框(至少在Ubuntu 22.04中(
它应该提示您刷新,之后您可以运行sudo apt update
,然后运行sudo apt install python3-venv
。
我希望这能有所帮助。