我试图删除 python 环境,我想我不小心删除了 fedora 的默认环境,并使 dnf 命令不可用。
我做了(不是连续的,但我认为这三个命令是相关的):
sudo rm /bin/python
sudo rm /usr/bin/python
sudo rm /bin/python3 /bin/python3.12 /bin/python-argcomplete-check-easy-install-script /bin/python-argcomplete-tcsh
然后我发现:
n349@fedora:~/Downloads$ sudo dnf upgrade
Place your right index finger on the fingerprint reader
^C[sudo] password for n349:
sudo: dnf: command not found
我尝试重新安装 dnf,但似乎 dnf-4.19.0-1 当前仍安装在我的计算机上,我无法再次执行此操作。
~/Downloads$ dnf --version
bash: dnf: command not found...
Install package 'dnf' to provide command 'dnf'? [N/y] y
* Waiting in queue...
* Loading list of packages.... Failed to install packages: dnf-4.19.0-1.fc39.noarch is already installed
n349@fedora:~/Downloads$ ls -l /usr/bin/dnf
lrwxrwxrwx. 1 root root 19 Mar 11 01:37 /usr/bin/dnf -> /usr/bin/dnf-4.19.0
我使用的是使用 dnf 从预装在 ThinkPad X1 Carbon 上的 Fedora 38 升级的 Fedora 39。
n349@fedora:~/Downloads$ uname -a
Linux fedora 6.7.7-200.fc39.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Mar 1 16:53:59 UTC 2024 x86_64 GNU/Linux
我在网上搜索并没有找到解决这个问题的方法,希望有人能帮助我恢复dnf的功能。
我尝试重新安装依赖项:
$ sudo rpm -ivh --force dnf-data-4.19.0-1.fc39.noarch.rpm \
dnf-automatic-4.19.0-1.fc39.noarch.rpm \
python3-dnf-4.19.0-1.fc39.noarch.rpm \
yum-4.19.0-1.fc39.noarch.rpm
sudo rpm -ivh --force dnf-4.19.0-1.fc39.noarch.rpm
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:dnf-data-4.19.0-1.fc39 ################################# [ 25%]
2:python3-dnf-4.19.0-1.fc39 ################################# [ 50%]
3:dnf-automatic-4.19.0-1.fc39 ################################# [ 75%]
4:yum-4.19.0-1.fc39 ################################# [100%]
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:dnf-4.19.0-1.fc39 ################################# [100%]
但它仍然不起作用,错误消息发生变化:
n349@fedora:~/Downloads$ dnf --version
bash: /usr/bin/dnf: cannot execute: required file not found
答案1
您需要重新安装 Python 解释器本身:
sudo rpm -Uvh https://dl.fedoraproject.org/pub/fedora/linux/updates/39/Everything/x86_64/Packages/p/python3-3.12.2-2.fc39.x86_64.rpm \
https://dl.fedoraproject.org/pub/fedora/linux/updates/39/Everything/x86_64/Packages/p/python3-libs-3.12.2-2.fc39.x86_64.rpm
为了将来参考,下面的所有内容/usr
(除了/usr/local
)都属于包管理器;您不得自行删除或更改其中的文件。如果您想删除 Python 3,请运行
sudo dnf remove python3
这将告诉您为什么不应尝试此操作,并为您提供添加选项以继续操作。
答案2
$ sudo rpm --reinstall --verbose --hash https://kojipkgs.fedoraproject.org/packages/python3.12/3.12.2/2.fc39/x86_64/python3-3.12.2-2.fc39.x86_64.rpm
Retrieving https://kojipkgs.fedoraproject.org/packages/python3.12/3.12.2/2.fc39/x86_64/python3-3.12.2-2.fc39.x86_64.rpm
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:python3-3.12.2-2.fc39 ################################# [ 50%]
Cleaning up / removing...
2:python3-3.12.2-2.fc39 ################################# [100%]
$ rpm --query python3
python3-3.12.2-2.fc39.x86_64
$ dnf --version
4.19.0
Installed: dnf-0:4.19.0-1.fc39.noarch at Mon 11 Mar 2024 07:38:12 AM GMT
Built : Fedora Project at Tue 20 Feb 2024 02:19:51 PM GMT
Installed: rpm-0:4.19.1.1-1.fc39.x86_64 at Wed 21 Feb 2024 07:00:46 PM GMT
Built : Fedora Project at Wed 07 Feb 2024 04:05:57 PM GMT