我已经删除了 usr/bin 中的 python 文件,无法重新安装它

我已经删除了 usr/bin 中的 python 文件,无法重新安装它

我是 Ubuntu 新手,不幸的是,我删除了 usr/bin 文件夹中的 3 个文件

python 2.7
python
python 2.6

现在我的更新管理器无法工作了,当我在 gnome 中输入 python 时,它说它不再存在。

请帮助我,我尝试了很多不同的方法,但就是不起作用。

我得到最接近的结果如下:

我输入了sudo apt-get -f install

我以为我已经解决了这个问题但是后来我收到一条错误消息 -

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  gir1.2-folks-0.6 gir1.2-polkit-1.0 libcogl5 mutter-common gir1.2-json-1.0
  libcaribou0 gir1.2-accountsservice-1.0 gir1.2-clutter-1.0 gir1.2-gkbd-3.0
  gir1.2-networkmanager-1.0 caribou libcogl-common libmutter0
  gir1.2-mutter-3.0 gjs gir1.2-caribou-1.0 libclutter-1.0-0
  gir1.2-telepathylogger-0.2 libclutter-1.0-common cups-pk-helper
  gir1.2-upowerglib-1.0 gir1.2-cogl-1.0 libmozjs185-1.0
  gir1.2-telepathyglib-0.12 gir1.2-gee-1.0 libgjs0c gnome-shell-common
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  ubuntu-sso-client
The following packages will be upgraded:
  ubuntu-sso-client
1 upgraded, 0 newly installed, 0 to remove and 35 not upgraded.
2 not fully installed or removed.
Need to get 0 B/57.7 kB of archives.
After this operation, 16.4 kB of additional disk space will be used.
Do you want to continue [Y/n]? y
Setting up python-minimal (2.7.2-7ubuntu2) ...
/var/lib/dpkg/info/python-minimal.postinst: 4: python2.7: not found
dpkg: error processing python-minimal (--configure):
 subprocess installed post-installation script returned error exit status 127
Errors were encountered while processing:
 python-minimal
E: Sub-process /usr/bin/dpkg returned an error code (1)

任何建议都值得感激!

答案1

我建议尝试运行 Live CD,找到您删除的那些文件,然后将它们复制到您安装的 /usr/bin 文件夹中。这应该不太难。您可能可以使用 Nautilus 挂载已安装的分区,打开它,然后尝试使用 GUI 进行复制。如果由于权限而出现错误,您可能需要使用终端将文件复制到(我相信)/media/*/usr/bin使用“sudo cp”,其中星号将是安装分区的名称。

作为新手,您不应该删除需要 root/admin 权限的文件(即使用 sudo 或同等权限),除非您完全确定这样做是否可行,或者至少将其复制到临时文件夹一段时间以确保这样做是否可行。这就是为什么只有某些用户才被允许这样做。

编辑:更多细节

我启动了我的 Live CD(12.04),并在您指定的目录中看到了 Python 2.7。我认为您不需要以前的版本。

使用 Nautilus,我可以单击我的真实安装,并且它会自动挂载到 /media,正如预期的那样。/media/usr/bin 中的文件归 root 所有,因此 nautilus 无法复制文件,除非它以 root 身份运行。

要重现这些文件,请执行以下操作:

  1. 通过在 Nautilus 中单击它来确保您的安装已安装,然后您应该会看到已安装分区的符号,即一种带有下方线条的向上箭头。

  2. 运行 bash 终端以获取命令行,然后输入cd /media/*/usr/bin,其中星号是您在 Nautilus 中看到的名称;您可以按 Tab 键自动完成,这样您就无需输入名称。

  3. 输入命令sudo cp -P /usr/bin/py* .,将会把python文件复制到当前目录,并保留链接(python链接到python2.7)。

这应该会替换已删除的文件。

如果您要重新安装它而不是先安装或卸载它,您可能能够使用软件中心或 apt-get 重新安装它。我认为错误可能是它认为它已安装,因此它不会复制文件的新版本。然后,它尝试访问该文件,但该文件并不像预期的那样存在。

答案2

尝试通过 apt-get 使用 --reinstall 选项重新安装 python 包:

$ sudo apt-get install --reinstall python-support python python-minimal python2.7-minimal python2.7 python2.6-minimal python2.6

相关内容