情況說(shuō)明
在ubuntu server 20.02下安裝了python 2.7, 3.8.5, 3.9。python默認(rèn)被設(shè)置在3.8.5下, 3.9是之前為了驗(yàn)證問(wèn)題安裝的,現(xiàn)在并沒(méi)有在使用。
當(dāng)我安裝pyserial包的時(shí)候,發(fā)現(xiàn)這臺(tái)server并沒(méi)有安裝pip,于是安裝pip:
sudo apt-get install python3-pip
再安裝pyserial包
sudo pip3 install pyserial
此時(shí)在python下import serial會(huì)提示找不到包,檢查發(fā)現(xiàn)默認(rèn)運(yùn)行的是python 3.8.5,但是pyserial被安裝在python3.9下面。由于所有的腳本都是跑在3.8.5下,因此希望pyserial也安裝到3.8.5下,卸載沒(méi)有使用的python3.9:
sudo pip3 uninstall pyserial
sudo apt-get --purge remove python3-pip
sudo apt-get --purge remove python3.9
此時(shí)為python 3.8.5安裝pip3和pyserial,發(fā)現(xiàn)還是被裝在/user/lib/python3.9下面,在/usr執(zhí)行下面命令
find -name python3.9*
發(fā)現(xiàn)python3.9并沒(méi)有清除干凈
。/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
于是手動(dòng)刪除
1
find -name python3.9* | xargs sudo rm -rf
然后噩夢(mèng)開(kāi)始,此時(shí)再安裝pip3,會(huì)提示已經(jīng)安裝
/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.
但執(zhí)行pip,又會(huì)說(shuō)找不到
/usr$ sudo pip3 install pyserial
sudo: unable to execute /usr/bin/pip3: No such file or directory
如果再次卸載pip3, 提示錯(cuò)誤
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
-
python
+關(guān)注
關(guān)注
56文章
4790瀏覽量
84599
原文標(biāo)題:手動(dòng)刪除python導(dǎo)致的問(wèn)題和恢復(fù)
文章出處:【微信號(hào):ZephyrProject,微信公眾號(hào):ZephyrProject】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論