我最近从源代码安装了 python 3.5,但我认为我在安装或链接过程中做错了什么。此后,我在安装任何 Ubuntu 软件包时都遇到了问题。例如,add-apt-repository 不起作用,即使重新安装了 software-properties-common 也是如此。
$ 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 安装才能运行。这些实用程序依赖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,因为它不会遮蔽系统实用程序所依赖的任何命令。