情況說明
在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
-
python
+關注
關注
56文章
4801瀏覽量
84878
原文標題:手動刪除python導致的問題和恢復
文章出處:【微信號:ZephyrProject,微信公眾號:ZephyrProject】歡迎添加關注!文章轉載請注明出處。
發布評論請先 登錄
相關推薦
評論