python - 如何在 Ubuntu 上将 python3 安装恢复为默认设置

标签 python python-3.x linux ubuntu

我正在使用 Ubuntu 21.04。我已删除 /usr/bin/python3/usr/lib/python3/因为某些软件包在二进制文件中出现错误。我的意思是重新安装python3到一个新的状态,但我不知道删除这些文件会破坏我的系统。
没有apt命令正在工作。他们给出一个错误说E: Sub-process /usr/bin/dpkg returned an error code (1) .这就是我使用 sudo apt --fix-broken install 得到的结果

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  g++-8 g++-9 libaccinj64-11.2 libcub-dev libcublas11 libcublaslt11 libcudart11.0
  libcufft10 libcufftw10 libcuinj64-11.2 libcupti-dev libcupti-doc libcupti11.2
  libcurand10 libcusolver11 libcusolvermg11 libcusparse11 libllvm11:i386 libluajit-5.1-2
  libluajit-5.1-common libnppc11 libnppial11 libnppicc11 libnppidei11 libnppif11
  libnppig11 libnppim11 libnppist11 libnppisu11 libnppitc11 libnpps11 libnvblas11
  libnvjpeg11 libnvrtc11.2 libnvtoolsext1 libnvvm4 libobs0 libthrust-dev libvdpau-dev
  node-html5shiv nsight-compute nsight-compute-target nsight-systems
  nsight-systems-target nvidia-cuda-gdb nvidia-cuda-toolkit-doc nvidia-opencl-dev
  nvidia-profiler nvidia-visual-profiler obs-plugins ocl-icd-opencl-dev opencl-c-headers
  opencl-clhpp-headers
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 8 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up tlpui (0.1.20210103-1~focal0) ...
/var/lib/dpkg/info/tlpui.postinst: 6: py3compile: not found
dpkg: error processing package tlpui (--configure):
 installed tlpui package post-installation script subprocess returned error exit status 12
7
Errors were encountered while processing:
 tlpui
E: Sub-process /usr/bin/dpkg returned an error code (1)
sudo dpkg --configure -a
Setting up tlpui (0.1.20210103-1~focal0) ...
/var/lib/dpkg/info/tlpui.postinst: 6: py3compile: not found
dpkg: error processing package tlpui (--configure):
 installed tlpui package post-installation script subprocess returned error exit status 127
Errors were encountered while processing:
 tlpui
如何在不重新安装操作系统的情况下将所有内容恢复到原始状态?我有 python3.9/usr/lib/ .我可以配置一切以使用这个 python,并让一切正常工作吗?
附言我忘了提 python3当我在终端中输入它时工作。更准确地说,当我使用 python3 时,我得到了这个
Python 3.8.7 (default, Jun 21 2021, 14:17:23) 
[GCC 10.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

最佳答案

你说你删除了/usr/bin/python3/usr/lib/python3/对于某些包装问题,除非您真的知道自己在做什么,否则绝对不鼓励这样做。处理 Python 包的更好方法是使用虚拟环境:Anaconda 和 pyenv 都是不错的选择。
按照他们的 Github repo 中的自述文件安装 pyenv 并不难:https://github.com/pyenv/pyenv
系统需要自己的 Python 来完成其任务。除非您在某些虚拟机上了解系统本身,否则不要手动删除系统文件夹中的任何内容。如果您使用的是虚拟机,则只需重新安装系统即可解决此问题。
如果您不想重新安装系统,最简单的方法是使用 VMWare、Virtual Box 或 Parallels Desktops 安装具有相同版本 Ubuntu 的虚拟机,并将您删除的文件复制回系统中。

关于python - 如何在 Ubuntu 上将 python3 安装恢复为默认设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69053024/

相关文章:

java - 从 jar 中提取后可执行文件将无法运行

python - pynput 不能处理大写和特殊字符——Mac OS

python - Scrapy 爬取链接列表

Python按索引从字符串中删除字符的最佳方法

python - 如何在 python 中将整数转换为单词?

linux - 对所有文件和子目录循环 cat 命令

python - Python 上的拉普拉斯过滤器无法按我的预期工作

python - 访问字典列表中的随机项目

python-3.x - 在 python 中保留所有字母和数字字符

linux - CURL 返回 "Unknown SSL protocol error"