升级到 22.04.2 后的 python3.8 和 pip

升级到 22.04.2 后的 python3.8 和 pip

我刚刚将 20.04 更新到 22.04,但在 Python 版本方面遇到了一些问题。在 20.04 上,我只有 Python 3.8,而现在在 22.04 上,我似乎只有 3.10。

(base) giammi56@giammi56-T440p:~$ ls /usr/bin/python*
/usr/bin/python
/usr/bin/python3.10-config
/usr/bin/python3-pasteurize
/usr/bin/python3
/usr/bin/python3-config
/usr/bin/python-argcomplete-check-easy-install-script3
/usr/bin/python3.10
/usr/bin/python3-futurize
/usr/bin/python-argcomplete-tcsh3
(base) giammi56@giammi56-T440p:~$ apt list | grep python3.8
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
libpython3.8-minimal/now 3.8.10-0ubuntu1~20.04.6 amd64 [residual-config]
python3.8-minimal/now 3.8.10-0ubuntu1~20.04.6 amd64 [residual-config]

在 20.04 中,我将 pip 与 pip3 设为别名,但是现在这可能会有问题吗?

(base) giammi56@giammi56-T440p:~$ pip --version
pip 23.0.1 from /home/giammi56/.local/lib/python3.10/site-packages/pip (python 3.10)
(base) giammi56@giammi56-T440p:~$ pip3 --version
pip 23.0.1 from /home/giammi56/.local/lib/python3.10/site-packages/pip (python 3.10)
(base) giammi56@giammi56-T440p:~$ pip3.8 --versionpip 23.0.1 from /home/giammi56/.local/lib/python3.10/site-packages/pip (python 3.10)

显然,pip 中安装的某些应用程序不起作用。Undervolt就是最好的例子。 命令可以识别,但不能识别sudo。 这里的关键是:

(base) giammi56@giammi56-T440p:~$ sudo undervolt --read
sudo: undervolt: command not found
(base) giammi56@giammi56-T440p:~$ undervolt
usage: undervolt [-h] [--version] [-v] [-f] [-r] [-t TEMP] [--temp-bat TEMP_BAT] [--throttlestop THROTTLESTOP]
[...]
(base) giammi56@giammi56-T440p:~$ locate undervolt
/etc/systemd/system/undervolt.service
/etc/systemd/system/hibernate.target.wants/undervolt.service
/etc/systemd/system/hybrid-sleep.target.wants/undervolt.service
/etc/systemd/system/multi-user.target.wants/undervolt.service
/etc/systemd/system/suspend.target.wants/undervolt.service
/home/giammi56/.cache/pip/wheels/ad/e5/e3/b8b0b993874dde746b5d3ffc16b122f15045fb98abd12d41ab/undervolt-0.3.0-py3-none-any.whl
/home/giammi56/.local/bin/undervolt
/home/giammi56/.local/lib/python3.8/site-packages/undervolt-0.3.0.dist-info
/home/giammi56/.local/lib/python3.8/site-packages/undervolt.py
/home/giammi56/.local/lib/python3.8/site-packages/__pycache__/undervolt.cpython-38.pyc
/home/giammi56/.local/lib/python3.8/site-packages/undervolt-0.3.0.dist-info/INSTALLER
/home/giammi56/.local/lib/python3.8/site-packages/undervolt-0.3.0.dist-info/METADATA
/home/giammi56/.local/lib/python3.8/site-packages/undervolt-0.3.0.dist-info/RECORD
/home/giammi56/.local/lib/python3.8/site-packages/undervolt-0.3.0.dist-info/REQUESTED
/home/giammi56/.local/lib/python3.8/site-packages/undervolt-0.3.0.dist-info/WHEEL
/home/giammi56/.local/lib/python3.8/site-packages/undervolt-0.3.0.dist-info/entry_points.txt
/home/giammi56/.local/lib/python3.8/site-packages/undervolt-0.3.0.dist-info/top_level.txt
/usr/local/bin/undervolt
/usr/local/lib/python3.8/dist-packages/undervolt-0.3.0.dist-info
/usr/local/lib/python3.8/dist-packages/undervolt.py
/usr/local/lib/python3.8/dist-packages/__pycache__/undervolt.cpython-38.pyc
/usr/local/lib/python3.8/dist-packages/undervolt-0.3.0.dist-info/INSTALLER
/usr/local/lib/python3.8/dist-packages/undervolt-0.3.0.dist-info/METADATA
/usr/local/lib/python3.8/dist-packages/undervolt-0.3.0.dist-info/RECORD
/usr/local/lib/python3.8/dist-packages/undervolt-0.3.0.dist-info/WHEEL
/usr/local/lib/python3.8/dist-packages/undervolt-0.3.0.dist-info/entry_points.txt
/usr/local/lib/python3.8/dist-packages/undervolt-0.3.0.dist-info/top_level.txt

我不知道该怎么做。建议线建议进行通用重新安装。我应该将所有 python3.8 程序升级到 3.10 吗?别名仍然有效吗?如果我有多个版本的 python,我是否应该从终端/.desktop 文件/. 服务调用具有正确版本的程序?任何帮助都将不胜感激。

答案1

在 20.04 中,我将 pip 与 pip3 设为别名,但是现在这可能会有问题吗?

我假设你所说的“现在”是指 Ubuntu 22.04......“假设您以后不打算安装和使用 Python2”...这应该不是问题,因为 Python3 是默认的且当前唯一可用的系统 Python。

显然,pip 中安装的某些应用程序不起作用。undervolt就是最好的例子。命令可以识别,但不能识别sudo

这实际上与升级基本无关,但undervolt与运行时用户的搜索路径sudoroot运行时的搜索路径相关sudo...本地安装的软件包的可执行文件(即,pip3 install ....通常放置在中~/.local/bin/),您可以使用例如进行验证,whereis undervolt这超出了搜索路径的范围root...另一方面,如果软件包是全局安装的,即,sudo pip3 install ...则它们的可执行文件(除其他差异外) 将在例如中可用/usr/local/bin/,因此可以很好地运行sudo

我应该将所有 python3.8 程序升级到 3.10 吗?

确保兼容性的一个好做法是使用 pip3-U选项将以前版本 Python3 上安装的模块/包更新为新升级版本可用的模块/包,例如:

pip3 install -U undervolt

或者sudo如果全局安装的话。

请参见:终端中的 Python 错误

如果我有多个版本的 python,我是否可以使用正确的版本从终端/.桌面文件/服务调用程序?

您可以选择在要运行的命令之前直接使用 Python3 可执行二进制文件,也可以选择在专用虚拟环境中运行...请参阅:

附加通知

虽然pip listpip install -U module/packagepip uninstall module/package将在你的默认系统 Python 版本上运行,例如python3.10在你的情况下,不同安装的 Python 版本模块也可以分别处理,即每个版本如下所示:

#List installed modules for python3.10:
python3.10 -m pip list

#List installed modules for python3.8:
python3.8 -m pip list

#Install/update modules for python3.10:
python3.10 -m pip install -U module/package

#Install/update modules for python3.8:
python3.8 -m pip install -U module/package

#Uninstall modules for python3.10:
python3.10 -m pip uninstall module/package

#Uninstall modules for python3.8:
python3.8 -m pip uninstall module/package

#Run installed modules for python3.10:
python3.10 -m module/package

#Run installed modules for python3.8:
python3.8 -m module/package

相关内容