升级 python 和 Anaconda(Debian 9)后 pip3 和 apt 出现错误

升级 python 和 Anaconda(Debian 9)后 pip3 和 apt 出现错误

为了安装 PyMC3,我从官方存储库安装了 Python 3.8,但没有意识到我已经有了 Anaconda2(带有 Python 3.6)。Python 3.8 运行良好,但我无法将其设为默认(即使尝试使用 updates-alternatives 和 PATH),而且我在使用 pip3 时遇到了问题

eric@debian:~$ sudo pip3 pymc3
Traceback (most recent call last):
  File "/usr/bin/pip3", line 9, in <module>
    from pip import main
ImportError: cannot import name 'main' from 'pip' (/usr/local/lib/python3.8/site-packages/pip/__init__.py)

我尝试了所有能找到的方法来修复 pip3(清除、强制卸载、重新安装等),但总是出现错误。因此,我决定删除 Anaconda2(顺便说一下,它已经损坏,因为无法使用conda命令)并安装 Anaconda3。它运行正常,但现在我遇到了另一个与 pip3 相关的问题:

eric@debian:~$ which pip3
/usr/bin/pip3
eric@debian:~$ which python3
/home/eric/anaconda3/bin/python3
eric@debian:~$ pip3 --version
bash: /usr/bin/pip3: /usr/bin/python3: bad interpreter: No such file or directory

当我尝试使用以下命令将其删除sudo apt remove python3-pip(以便重新安装它):

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  python3-crypto python3-keyring python3-keyrings.alt python3-secretstorage
  python3-wheel python3-xdg
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  python3-pip
0 upgraded, 0 newly installed, 1 to remove and 101 not upgraded.
1 not fully installed or removed.
After this operation, 599 kB disk space will be freed.
Do you want to continue? [Y/n] y
/bin/sh: 1: /usr/bin/apt-listchanges: not found
E: Sub-process /usr/bin/apt-listchanges --apt || test $? -lt 10 returned an error code (1)
E: Failure running script /usr/bin/apt-listchanges --apt || test $? -lt 10

我尝试了 apt autoremove,它抛出了相同的 apt-listchange 错误。阅读相关文章后,我尝试了:

eric@debian:~$ sudo dpkg-reconfigure apt-listchanges
/usr/sbin/dpkg-reconfigure: apt-listchanges is broken or not fully installed

eric@debian:~$ sudo dpkg --purge apt-listchanges
(Reading database ... 305288 files and directories currently installed.)
Removing apt-listchanges (3.10) ...
/var/lib/dpkg/info/apt-listchanges.prerm: 6: /var/lib/dpkg/info/apt-listchanges.prerm: py3clean: not found
dpkg: error processing package apt-listchanges (--purge):
 subprocess installed pre-removal script returned error exit status 127
Deferring configuration of apt-listchanges until python3 is available
/var/lib/dpkg/info/apt-listchanges.postinst: 186: /var/lib/dpkg/info/apt-listchanges.postinst: py3compile: not found
dpkg: error while cleaning up:
 subprocess installed post-installation script returned error exit status 127
Errors were encountered while processing:
 apt-listchanges

根据我读过的相关文章,大多数情况下,重新安装损坏的 apt-listchanges 可以解决问题,但我做不到。如果您需要更多信息,请告诉我。谢谢!

相关内容