运行“sudo apt purge python”导致整个系统崩溃

运行“sudo apt purge python”导致整个系统崩溃

为什么如果我运行以下命令,Ubuntu Focal Fossa 20.04 LTS 会彻底崩溃?

sudo apt purge python*

apt在我开始该过程之前,我没有收到有关该操作的任何警报!

我怎样才能避免这种危险的软件问题以及我怎样才能为将来的类似情况做好准备?

答案1

为什么如果我运行以下命令,Ubuntu Focal Fossa 20.04 LTS 会彻底崩溃?

sudo apt purge python*

Python 是 Ubuntu 的核心组件,因此 Ubuntu 严重依赖它。删除它会导致系统完全崩溃,正如您所见。虽然可能会有修复方法Ubuntu 下安装 Python 断网后,最好的选择就是彻底重装系统。


apt在我开始该过程之前,我没有收到有关该操作的任何警报!

我不确定这apt是否提醒了你删除了几个软件包。运行python3从我的系统中清除的模拟(使用 的apt标志-s- 请参阅man apt),返回以下内容:

$ apt -s purge python3
NOTE: This is only a simulation!
      apt needs root privileges for real execution.
      Keep also in mind that locking is deactivated,
      so don't depend on the relevance to the real current situation!
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  apg apport-symptoms aptdaemon-data avahi-utils cups-pk-helper dc dconf-cli dctrl-tools distro-info distro-info-data docbook-xml evolution-data-server evolution-data-server-common fonts-cantarell fprintd
  geoip-database gir1.2-accountsservice-1.0 gir1.2-atspi-2.0 gir1.2-clutter-1.0 gir1.2-clutter-gst-3.0 gir1.2-cogl-1.0 gir1.2-coglpango-1.0 gir1.2-dbusmenu-glib-0.4 gir1.2-dee-1.0 gir1.2-gck-1 gir1.2-gcr-3
  gir1.2-gdm-1.0 gir1.2-geoclue-2.0 gir1.2-gnomebluetooth-1.0 gir1.2-goa-1.0 gir1.2-graphene-1.0 gir1.2-gtkclutter-1.0 gir1.2-gtksource-3.0 gir1.2-gweather-3.0 gir1.2-handy-0.0 gir1.2-ibus-1.0 gir1.2-json-1.0
  gir1.2-keybinder-3.0 gir1.2-mutter-6 gir1.2-nm-1.0 gir1.2-nma-1.0 gir1.2-notify-0.7 gir1.2-packagekitglib-1.0 gir1.2-polkit-1.0 gir1.2-rsvg-2.0 gir1.2-secret-1 gir1.2-snapd-1 gir1.2-unity-5.0
  gir1.2-upowerglib-1.0 gir1.2-vte-2.91 gkbd-capplet gnome-control-center-faces gnome-session-bin gnome-session-common gnome-shell-common gnome-startup-applications ibus-data ippusbxd libarchive-tools
  libatomic1:i386 libboost-python1.71.0 libbsd0:i386 libcamel-1.2-62 libchromaprint-tools libcolord-gtk1 libdiscid0 libdrm-amdgpu1:i386 libdrm-intel1:i386 libdrm-nouveau2:i386 libdrm-radeon1:i386 libdrm2:i386
  libebackend-1.2-10 libebook-1.2-20 libebook-contacts-1.2-3 libecal-2.0-1 libedata-book-1.2-26 libedata-cal-2.0-1 libedataserver-1.2-24 libedataserverui-1.2-2 libedit2:i386 libelf1:i386 libetonyek-0.1-1
  libexpat1:i386 libexpat1-dev libffi7:i386 libfluidsynth2 libfprint-2-2 libgdata-common libgdata22 libgeoip1 libgl1:i386 libgl1-mesa-dri:i386 libglapi-mesa:i386 libglvnd0:i386 libglx-mesa0:i386 libglx0:i386
  libgnomekbd-common libgnomekbd8 libgsoap-2.8.91 libgssdp-1.2-0 libgupnp-1.2-0 libgupnp-av-1.0-2 libgupnp-dlna-2.0-3 libhpmud0 libimagequant0 libinstpatch-1.0-2 libjpeg-turbo-progs libjuh-java libjurt-java
  libkeybinder-3.0-0 libldb2 libllvm12:i386 liblzf1 libmediaart-2.0-0 libmikmod3 libmodplug1 libmspub-0.1-1 libmtp-common libmtp-runtime libmtp9 libmutter-6-0 libmwaw-0.3-3 libnetplan0 libnfs13
  libnvidia-cfg1-450-server libnvidia-common-450-server libnvidia-compute-450-server:i386 libnvidia-decode-450-server libnvidia-decode-450-server:i386 libnvidia-encode-450-server
  libnvidia-encode-450-server:i386 libnvidia-extra-450-server libnvidia-fbc1-450-server libnvidia-fbc1-450-server:i386 libnvidia-gl-450-server libnvidia-gl-450-server:i386 libnvidia-ifr1-450-server
  libnvidia-ifr1-450-server:i386 liborcus-0.15-0 libpam-fprintd libpciaccess0:i386 libphonenumber7 libportmidi0 libprotobuf17 libpython3-dev libpython3-stdlib libpython3.8-dev libqt5designer5 libqt5help5
  libqt5multimedia5 libqt5multimedia5-plugins libqt5multimediagsttools5 libqt5multimediawidgets5 libqt5opengl5 libqt5sql5 libqt5sql5-sqlite libqt5test5 libqt5xml5 libreoffice-style-tango libridl-java
  librygel-core-2.6-2 librygel-db-2.6-2 librygel-renderer-2.6-2 librygel-server-2.6-2 libsane-hpaio libsdl-image1.2 libsdl-mixer1.2 libsdl-ttf2.0-0 libsdl1.2debian libsensors5:i386 libstdc++6:i386 libtalloc2
  libtevent0 libtorrent-rasterbar9 libunoil-java libutempter0 libva-wayland2 libvncserver1 libvte-2.91-0 libvte-2.91-common libvulkan1:i386 libwayland-client0:i386 libwbclient0 libwhoopsie-preferences0
  libwps-0.4-4 libx11-6:i386 libx11-xcb1:i386 libxatracker2 libxau6:i386 libxcb-dri2-0:i386 libxcb-dri3-0:i386 libxcb-glx0:i386 libxcb-present0:i386 libxcb-randr0:i386 libxcb-res0 libxcb-shm0:i386
  libxcb-sync1:i386 libxcb-xfixes0:i386 libxcb-xv0 libxcb1:i386 libxdmcp6:i386 libxext6:i386 libxfixes3:i386 libxfont2 libxklavier16 libxnvctrl0 libxshmfence1:i386 libxvmc1 libxxf86vm1:i386 libyelp0
  linux-headers-5.4.0-26 linux-headers-5.4.0-26-generic linux-headers-5.8.0-63-generic linux-hwe-5.8-headers-5.8.0-63 mesa-vulkan-drivers:i386 mobile-broadband-provider-info mscompress mutter mutter-common
  network-manager-gnome nvidia-compute-utils-450-server nvidia-kernel-common-450-server nvidia-kernel-source-450-server nvidia-utils-450-server plymouth-label policykit-1-gnome printer-driver-hpcups
  python-apt-common python-pip-whl python3-minimal python3.8 python3.8-dev python3.8-minimal rygel sgml-base sgml-data switcheroo-control timgm6mb-soundfont whoopsie-preferences x11-session-utils x11-xkb-utils
  xbrlapi xfonts-base xfonts-encodings xfonts-scalable xfonts-utils xinit xinput xml-core xserver-common xserver-xephyr xserver-xorg-core xserver-xorg-input-all xserver-xorg-input-libinput
  xserver-xorg-input-wacom xserver-xorg-legacy xserver-xorg-video-all xserver-xorg-video-amdgpu xserver-xorg-video-ati xserver-xorg-video-fbdev xserver-xorg-video-intel xserver-xorg-video-nouveau
  xserver-xorg-video-nvidia-450-server xserver-xorg-video-qxl xserver-xorg-video-radeon xserver-xorg-video-vesa xserver-xorg-video-vmware xterm xwayland yelp-xsl zlib1g-dev
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
  policykit-1-gnome
The following packages will be REMOVED:
  apparmor* apport* apport-gtk* aptdaemon* apturl* apturl-common* autokey-common* autokey-gtk* celluloid* chrome-gnome-shell* command-not-found* deluge* deluge-common* deluge-gtk* dkms* exfalso* firefox*
  foomatic-db-compressed-ppds* gdm3* gnome-control-center* gnome-getting-started-docs* gnome-getting-started-docs-el* gnome-menus* gnome-online-accounts* gnome-session* gnome-shell*
  gnome-shell-extension-appindicator* gnome-shell-extension-desktop-icons* gnome-shell-extension-prefs* gnome-shell-extension-ubuntu-dock* gnome-tweaks* gnome-user-docs* gnome-user-docs-el* gufw* gvfs-backends*
  hplip* hplip-data* ibus* ibus-table* imgsizer* language-selector-common* language-selector-gnome* libmpv1* libsmbclient* lsb-release* mpv* nautilus-share* netplan.io* networkd-dispatcher*
  nvidia-dkms-450-server* nvidia-driver-450-server* nvidia-prime* nvidia-settings* openprinting-ppds* orca* picard* plymouth-theme-spinner* plymouth-theme-ubuntu-text* printer-driver-foo2zjs*
  printer-driver-foo2zjs-common* printer-driver-m2300w* printer-driver-postscript-hp* printer-driver-ptouch* printer-driver-pxljr* printer-driver-sag-gdi* python3* python3-appdirs* python3-apport* python3-apt*
  python3-aptdaemon* python3-aptdaemon.gtk3widgets* python3-attr* python3-automat* python3-babelfish* python3-blinker* python3-brlapi* python3-bs4* python3-cairo* python3-certifi* python3-cffi-backend*
  python3-chardet* python3-click* python3-colorama* python3-commandnotfound* python3-constantly* python3-cryptography* python3-cups* python3-cupshelpers* python3-dateutil* python3-dbus* python3-debconf*
  python3-debian* python3-decorator* python3-defer* python3-dev* python3-distro* python3-distro-info* python3-distupgrade* python3-distutils* python3-dogpile.cache* python3-entrypoints* python3-enzyme*
  python3-feedparser* python3-gdbm* python3-geoip* python3-gi* python3-gi-cairo* python3-greenlet* python3-guessit* python3-hamcrest* python3-html5lib* python3-httplib2* python3-hyperlink* python3-ibus-1.0*
  python3-idna* python3-incremental* python3-jwt* python3-keyring* python3-launchpadlib* python3-lazr.restfulclient* python3-lazr.uri* python3-lib2to3* python3-libdiscid* python3-libtorrent* python3-louis*
  python3-lxml* python3-macaroonbakery* python3-mako* python3-markupsafe* python3-msgpack* python3-musicbrainzngs* python3-mutagen* python3-nacl* python3-neovim* python3-netifaces* python3-numpy*
  python3-oauthlib* python3-olefile* python3-openssl* python3-pbr* python3-pexpect* python3-pil* python3-pip* python3-pkg-resources* python3-problem-report* python3-protobuf* python3-ptyprocess* python3-pyasn1*
  python3-pyasn1-modules* python3-pyatspi* python3-pygame* python3-pyinotify* python3-pymacaroons* python3-pynvim* python3-pyqt5* python3-pyqt5.qtmultimedia* python3-pysrt* python3-rarfile* python3-rebulk*
  python3-rencode* python3-renderpm* python3-reportlab* python3-reportlab-accel* python3-requests* python3-requests-unixsocket* python3-rfc3339* python3-secretstorage* python3-service-identity*
  python3-setproctitle* python3-setuptools* python3-simplejson* python3-sip* python3-six* python3-software-properties* python3-soupsieve* python3-speechd* python3-stevedore* python3-subliminal* python3-systemd*
  python3-talloc* python3-toposort* python3-twisted* python3-twisted-bin* python3-tz* python3-uno* python3-update-manager* python3-urllib3* python3-wadllib* python3-webencodings* python3-wheel* python3-xdg*
  python3-xkit* python3-xlib* python3-yaml* python3-zope.interface* quodlibet* ranger* samba-libs* screen-resolution-extra* snapd* software-properties-common* software-properties-gtk* subliminal*
  system-config-printer* system-config-printer-common* system-config-printer-udev* ubuntu-advantage-tools* ubuntu-desktop* ubuntu-desktop-minimal* ubuntu-docs* ubuntu-drivers-common* ubuntu-minimal*
  ubuntu-release-upgrader-core* ubuntu-release-upgrader-gtk* ubuntu-session* ubuntu-standard* ufw* unattended-upgrades* update-manager* update-manager-core* update-notifier* update-notifier-common* virtualbox*
  virtualbox-dkms* virtualbox-qt* xorg* xserver-xorg* yelp*

显然这些都是很多依赖python3并被删除的软件包,您可以看到其中有很多关键软件包。当您运行 时sudo apt purge python*,我猜在确认删除软件包之前会向您显示类似的输出。因此apt不提醒您并不完全正确。


我怎样才能避免这种危险的软件问题以及我怎样才能为将来的类似情况做好准备?

  1. 不要删除默认的 Python 安装!如果你需要除预装版本之外的 Python 版本,我强烈建议你使用虚拟环境来安装。你可以看看venv或者Anaconda Python 发行版(我个人使用并推荐)。

  2. 如果您没有充分的理由,请不要弄乱核心组件。

  3. apt在删除您不知道的软件包之前,您可以使用的标志运行删除模拟,而不实际删除任何内容-s(正如我上面所做的那样)。

  4. 备份您的重要个人文件和配置。

答案2

删除 Python 就是删除操作系统的一部分。

当您运行该命令时sudo apt purge python*,它会带来多项职责。

  1. 您正在以 的身份运行它sudo,这意味着您应该知道自己在做什么。
  2. 您正在删除默认系统包——同样,您应该事先了解这件事的后果。

类似于此的是,删除system32Windows 中的文件夹(包含大量系统可执行文件和库的文件夹),然后抱怨操作系统无法运行。

相关内容