手动删除python导致的问题如何解决?

描述

情况说明

在ubuntu server 20.02下安装了python 2.7, 3.8.5, 3.9。python默认被设置在3.8.5下, 3.9是之前为了验证问题安装的,现在并没有在使用。

当我安装pyserial包的时候,发现这台server并没有安装pip,于是安装pip:

sudo apt-get install python3-pip

再安装pyserial包

sudo pip3 install pyserial

此时在python下import serial会提示找不到包,检查发现默认运行的是python 3.8.5,但是pyserial被安装在python3.9下面。由于所有的脚本都是跑在3.8.5下,因此希望pyserial也安装到3.8.5下,卸载没有使用的python3.9:

sudo pip3 uninstall pyserial

sudo apt-get --purge remove python3-pip

sudo apt-get --purge remove python3.9

此时为python 3.8.5安装pip3和pyserial,发现还是被装在/user/lib/python3.9下面,在/usr执行下面命令

find -name python3.9*

发现python3.9并没有清除干净

。/bin/python3.9

。/lib/python3.9

。/share/man/man1/python3.9.1.gz

。/share/binfmts/python3.9

。/share/doc/python3.9-doc

。/share/doc/python3.9

。/share/doc/python3.9/html/python3.9.devhelp.gz

。/share/doc/python3.9-minimal

。/share/doc-base/python3.9-lib

。/share/doc-base/python3.9-inst

。/share/doc-base/python3.9-api

。/share/doc-base/python3.9-tut

。/share/doc-base/python3.9-new

。/share/doc-base/python3.9-ext

。/share/doc-base/python3.9-dist

。/share/doc-base/python3.9-ref

。/share/lintian/overrides/python3.9-doc

。/share/lintian/overrides/python3.9-minimal

。/share/devhelp/books/python3.9

。/share/info/python3.9.info.gz

。/share/info/python3.9

。/include/python3.9

。/include/x86_64-linux-gnu/python3.9

。/include/x86_64-linux-gnu/python3.9d

。/include/python3.9d

于是手动删除

1

find -name python3.9* | xargs sudo rm -rf

然后噩梦开始,此时再安装pip3,会提示已经安装

/usr$ sudo apt-get install python3-pip

Reading package lists.。。 Done

Building dependency tree

Reading state information.。。 Done

python3-pip is already the newest version (20.0.2-5ubuntu1.5)。

0 upgraded, 0 newly installed, 0 to remove and 57 not upgraded.

但执行pip,又会说找不到

/usr$ sudo pip3 install pyserial

sudo: unable to execute /usr/bin/pip3: No such file or directory

如果再次卸载pip3, 提示错误

Removing python3-pip (20.0.2-5ubuntu1.5) 。。。

/var/lib/dpkg/info/python3-pip.prerm: 6: py3clean: not found

dpkg: error processing package python3-pip (--remove):

installed python3-pip package pre-removal script subprocess returned error exit status 127

dpkg: too many errors, stopping

/var/lib/dpkg/info/python3-pip.postinst: 6: py3compile: not found

dpkg: error while cleaning up:

installed python3-pip package post-installation script subprocess returned error exit status 127

Errors were encountered while processing:

python3-pip

Processing was halted because there were too many errors.

E: Sub-process /usr/bin/dpkg returned an error code (1)

解决方法

sudo apt-get update

sudo apt-get upgrade

sudo apt --fix-broken install

dpkg --configure -a

apt-get download python3-minimal

sudo dpkg -i *python3*.deb

sudo apt-get -f install

sudo apt-get install python3-pip

sudo pip3 install pyserial

编辑:jq

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分