在 ubuntu 22.04 上安装 python3.11 和库(numpy、matplotlib、scipy)

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

我想升级我在 Ubuntu 22.04 桌面上使用的 python、numpy、matplotlib 和 scipy 版本,以镜像我笔记本电脑上的版本。

运行

apt list --installed
显示在为我设置桌面时,通过
apt-get
安装了以下软件包(以及许多其他 python 软件包):

python3-matplotlib-inline/jammy,jammy,now 0.1.3-1 all [installed]
python3-matplotlib/jammy,now 3.5.1-2build1 amd64 [installed]
python3-numpy/jammy-updates,jammy-security,now 1:1.21.5-1ubuntu22.04.1 amd64 [installed,automatic]
python3-scipy/jammy,now 1.8.0-1exp2ubuntu1 amd64 [installed,automatic]
python3.10-dev/jammy-updates,jammy-security,now 3.10.12-1~22.04.3 amd64 [installed,automatic]
python3.10-minimal/jammy-updates,jammy-security,now 3.10.12-1~22.04.3 amd64 [installed,automatic]

特别是最后两个显示我正在运行 python 3.10.12。

为了升级到 python 3.11,我运行了

$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt install python3.11-full

这给了我裸露的 python,但我现在在升级我的库时遇到了麻烦,我想通过 pip 来管理它。我特别明白

$ pip install numpy --upgrade
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: numpy in ./.local/lib/python3.10/site-packages (1.26.4)

当我尝试升级 matplotlib 时类似 - 因为这些软件包已经安装,pip 不想碰它们。

有没有办法可以在我的系统上安装新软件包并“指向”我安装的 python 3.11?理想情况下,我希望在系统范围内使用它,而不是使用虚拟环境(主要是因为我不理解它们,我只是希望能够从任何地方调用我的脚本)。

至少我想知道如何升级到 matplotlib 3.8.2 并在运行 python 3.10 内核而不是当前的 mpl 3.5.1 时导入它,但理想情况下升级所有内容。

python ubuntu installation apt
1个回答
0
投票

检查你使用的Python命令,可能与系统一捆绑在一起。为已安装的 python 3.11 创建虚拟环境(python -m venv directory_name),激活它并使用 venv 中的 pip。根据我的经验,这是在 ubuntu 上使用所需 python 版本的最简单方法。

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