
我最近從原始程式碼安裝了 python 3.5,但我認為我在安裝或連結過程中做錯了什麼。此後我在安裝任何 Ubuntu 軟體包時都遇到問題。例如,即使在重新安裝 software-properties-common 後,add-apt-repository 也不起作用。
$ add-apt-repository
bash: /usr/bin/add-apt-repository: /usr/bin/python3: bad interpreter: No such file or directory
另外, apt-get install 會給我這個錯誤
$ sudo apt-get install libraw-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
libraw-dev
0 upgraded, 1 newly installed, 0 to remove and 229 not upgraded.
3 not fully installed or removed.
Need to get 382 kB/391 kB of archives.
After this operation, 1,588 kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu/ trusty/main libraw-dev amd64 0.15.4-1 [382 kB]
Fetched 382 kB in 0s (651 kB/s)
Selecting previously unselected package libraw-dev:amd64.
(Reading database ... 295477 files and directories currently installed.)
Preparing to unpack .../libraw-dev_0.15.4-1_amd64.deb ...
Unpacking libraw-dev:amd64 (0.15.4-1) ...
Setting up python3.4 (3.4.3-1ubuntu1~14.04.5) ...
Could not find platform independent libraries <prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'
Aborted
dpkg: error processing package python3.4 (--configure):
subprocess installed post-installation script returned error exit status 134
Setting up python3-commandnotfound (0.3ubuntu12) ...
/var/lib/dpkg/info/python3-commandnotfound.postinst: 6: /var/lib/dpkg/info/python3-commandnotfound.postinst: py3compile: not found
dpkg: error processing package python3-commandnotfound (--configure):
subprocess installed post-installation script returned error exit status 127
dpkg: error processing package software-properties-common (--configure):
package is in a very bad inconsistent state; you should
reinstall it before attempting configuration
Setting up libraw-dev:amd64 (0.15.4-1) ...
Errors were encountered while processing:
python3.4
python3-commandnotfound
software-properties-common
E: Sub-process /usr/bin/dpkg returned an error code (1)
另外,嘗試新增 ppa 會出現以下錯誤
$ sudo add-apt-repository ppa:dhor/myway
sudo: unable to execute /usr/bin/add-apt-repository: No such file or directory
這是怎麼回事,有什麼想法嗎?
答案1
首先,需要恢復Python 3的核心:
sudo apt install -f --reinstall python3 python3.4 python3-minimal python3.4-minimal libpython3.4-minimal
如果由於依賴 Python 3 的軟體包安裝了一半而導致此方法不起作用,請手動下載並安裝它們:
cd /tmp apt-get download python3 python3.4 python3-minimal python3.4-minimal libpython3.4-minimal sudo dpkg -i *python3*.deb sudo apt install -f
安裝該
debsums
套件並執行包健全性檢查驗證剩餘軟體包的完整性並在必要時重新安裝它們。
答案2
Ubuntu 附帶了自己的 Python 安裝,系統實用程式需要依賴它才能運作。這些實用程式依賴python
、python2
和python3
指向這些系統安裝。不幸的是,當從原始程式碼建置/安裝Python時,標準make install
會安裝新的python
/ python2
(對於Python 2.x)或python3
(對於Python 3.x)二進位文件,這最終可能會影響系統Python安裝並破壞一些東西。
一旦你修復了你的系統(David 的答案應該能讓你繼續下去),你的從源代碼編譯的 Python 應該用 來(重新)安裝make altinstall
,這將放棄python3
並僅將解釋器安裝為特定於版本的python3.5
.這是安裝您自己的 Python 而不干擾系統 Python 的安全方法,因為它不會影響系統實用程式依賴的任何命令。