apt-get/dpkg 无法配置任何与 python 相关的包

apt-get/dpkg 无法配置任何与 python 相关的包

我最近将 Python 2.7 安装到了 /usr/local/bin。现在,每次我尝试使用 apt-get 时,都会在某些 Python 包上失败,如下所示:

root@lebowski:/usr/local/bin# apt-get upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
6 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue [Y/n]? y
Traceback (most recent call last):
  File "/usr/bin/apt-listchanges", line 28, in <module>
    import apt_pkg
ImportError: No module named apt_pkg
Setting up python-imaging (1.1.7-2) ...
Traceback (most recent call last):
  File "/usr/local/bin/lib/python2.6/runpy.py", line 122, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/local/bin/lib/python2.6/runpy.py", line 34, in _run_code
    exec code in run_globals
  File "/usr/local/bin/lib/python2.6/py_compile.py", line 168, in <module>
    sys.exit(main())
  File "/usr/local/bin/lib/python2.6/py_compile.py", line 160, in main
    compile(filename, doraise=True)
  File "/usr/local/bin/lib/python2.6/py_compile.py", line 115, in compile
    f = open(file, 'U')
IOError: [Errno 2] No such file or directory: '-'
Traceback (most recent call last):
  File "/usr/bin/pycompile", line 320, in <module>
    main()
  File "/usr/bin/pycompile", line 299, in main
    options.force, options.optimize, e_patterns)
  File "/usr/bin/pycompile", line 217, in compile
    pipe.send(fn)
  File "/usr/bin/pycompile", line 180, in py_compile
    stdin.write(filename + '\n')
IOError: [Errno 32] Broken pipe
dpkg: error processing python-imaging (--configure):
 subprocess installed post-installation script returned error exit status 1
Setting up python-lxml (2.2.8-2) ...
configured to not write apport reports
                                      Traceback (most recent call last):
  File "/usr/local/bin/lib/python2.6/runpy.py", line 122, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/local/bin/lib/python2.6/runpy.py", line 34, in _run_code
    exec code in run_globals
  File "/usr/local/bin/lib/python2.6/py_compile.py", line 168, in <module>
    sys.exit(main())
  File "/usr/local/bin/lib/python2.6/py_compile.py", line 160, in main
    compile(filename, doraise=True)
  File "/usr/local/bin/lib/python2.6/py_compile.py", line 115, in compile
    f = open(file, 'U')
IOError: [Errno 2] No such file or directory: '-'
Traceback (most recent call last):
  File "/usr/bin/pycompile", line 320, in <module>
    main()
  File "/usr/bin/pycompile", line 299, in main
    options.force, options.optimize, e_patterns)
  File "/usr/bin/pycompile", line 217, in compile
    pipe.send(fn)
  File "/usr/bin/pycompile", line 180, in py_compile
    stdin.write(filename + '\n')
IOError: [Errno 32] Broken pipe
dpkg: error processing python-lxml (--configure):
 subprocess installed post-installation script returned error exit status 1
Setting up python-reportlab (2.4-4) ...
configured to not write apport reports
                                      Traceback (most recent call last):
  File "/usr/local/bin/lib/python2.6/runpy.py", line 122, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/local/bin/lib/python2.6/runpy.py", line 34, in _run_code
    exec code in run_globals
  File "/usr/local/bin/lib/python2.6/py_compile.py", line 168, in <module>
    sys.exit(main())
  File "/usr/local/bin/lib/python2.6/py_compile.py", line 160, in main
    compile(filename, doraise=True)
  File "/usr/local/bin/lib/python2.6/py_compile.py", line 115, in compile
    f = open(file, 'U')
IOError: [Errno 2] No such file or directory: '-'
Traceback (most recent call last):
  File "/usr/bin/pycompile", line 320, in <module>
    main()
  File "/usr/bin/pycompile", line 299, in main
    options.force, options.optimize, e_patterns)
  File "/usr/bin/pycompile", line 217, in compile
    pipe.send(fn)
  File "/usr/bin/pycompile", line 180, in py_compile
    stdin.write(filename + '\n')
IOError: [Errno 32] Broken pipe
dpkg: error processing python-reportlab (--configure):
 subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of python-reportlab-accel:
 python-reportlab-accel depends on python-reportlab (>= 2.4-4); however:
  Package python-reportlab is not configured yet.
dpkg: error processing python-reportlab-accel (--configure):
 dependency problems - leaving unconfigured
Setting up python-xapian (1.2.3-3) ...
configured to not write apport reports
                                      configured to not write apport reports
                                                                            Traceback (most recent call last):
  File "/usr/bin/pycentral", line 2334, in <module>
    main()
  File "/usr/bin/pycentral", line 2328, in main
    rv = action.run(global_options)
  File "/usr/bin/pycentral", line 1477, in run
    runtimes = get_installed_runtimes()
  File "/usr/bin/pycentral", line 278, in get_installed_runtimes
    default_version = pyversions.default_version(version_only=True)
  File "/usr/share/pycentral-data/pyversions.py", line 172, in default_version
    raise ValueError, "/usr/bin/python does not match the python default version. It must be reset to point to %s" % debian_default
ValueError: /usr/bin/python does not match the python default version. It must be reset to point to python2.6
dpkg: error processing python-xapian (--configure):
 subprocess installed post-installation script returned error exit status 1
configured to not write apport reports
                                      dpkg: dependency problems prevent configuration of rst2pdf:
 rst2pdf depends on python-reportlab; however:
  Package python-reportlab is not configured yet.
dpkg: error processing rst2pdf (--configure):
 dependency problems - leaving unconfigured
configured to not write apport reports
                                      Errors were encountered while processing:
 python-imaging
 python-lxml
 python-reportlab
 python-reportlab-accel
 python-xapian
 rst2pdf
E: Sub-process /usr/bin/dpkg returned an error code (1)

我尝试使用 2.6 或 2.7 作为我的默认版本,但这不会影响问题。这似乎是 dpkg 的一个问题,使用 dpkg --configure python 也无济于事。

我有点束手无策了,如果有人能对这个问题提供一些见解,我将不胜感激。

编辑:其他相关信息:

root@lebowski:/usr/local/bin# python -V
Python 2.6.9

root@lebowski:/usr/local/bin# ls -al /usr/bin/py*
-rwxr-xr-x 1 root root    3752 Sep 14  2010 /usr/bin/py3_compilefiles
-rwxr-xr-x 1 root root   95845 Sep 14  2010 /usr/bin/pycentral
-rwxr-xr-x 1 root root    4599 May  5  2012 /usr/bin/pyclean
-rwxr-xr-x 1 root root   12783 May  5  2012 /usr/bin/pycompile
-rwxr-xr-x 1 root root    3723 Sep 14  2010 /usr/bin/py_compilefiles
lrwxrwxrwx 1 root root       8 Aug 28 16:06 /usr/bin/pydoc -> pydoc2.6
-rwxr-xr-x 1 root root      79 Dec 26  2010 /usr/bin/pydoc2.6
lrwxrwxrwx 1 root root      12 Aug 28 16:06 /usr/bin/pygettext -> pygettext2.6
-rwxr-xr-x 1 root root   22103 Dec 26  2010 /usr/bin/pygettext2.6
-rwxr-xr-x 1 root root      67 Mar 20  2010 /usr/bin/pygmentize
lrwxrwxrwx 1 root root      24 Aug 28 16:06 /usr/bin/python -> /etc/alternatives/python
lrwxrwxrwx 1 root root      24 Aug 28 11:50 /usr/bin/python2.6 -> /usr/local/bin/python2.6
-rwxr-xr-x 1 root root    1452 Dec 26  2010 /usr/bin/python2.6-config
-rwxr-xr-x 1 root root 5606639 Dec 26  2010 /usr/bin/python2.6-dbg
-rwxr-xr-x 1 root root    1456 Dec 26  2010 /usr/bin/python2.6-dbg-config
lrwxrwxrwx 1 root root      24 Aug 28 13:31 /usr/bin/python2.7 -> /usr/local/bin/python2.7
lrwxrwxrwx 1 root root      16 Sep 19  2013 /usr/bin/python-config -> python2.6-config
-rwxr-xr-x 1 root root    4119 Jan 24  2009 /usr/bin/python_count
lrwxrwxrwx 1 root root      13 Sep 25  2013 /usr/bin/python-dbg -> python2.6-dbg
lrwxrwxrwx 1 root root      20 Sep 25  2013 /usr/bin/python-dbg-config -> python2.6-dbg-config
lrwxrwxrwx 1 root root      29 Aug 28 16:06 /usr/bin/pyversions -> ../share/python/pyversions.py

root@lebowski:/usr/local/bin# update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).

  Selection    Path                      Priority   Status
------------------------------------------------------------
  0            /usr/bin/python2.6         20        auto mode
* 1            /usr/bin/python2.6         20        manual mode
  2            /usr/local/bin/python2.7   10        manual mode

root@lebowski:/usr/local/bin# ls -al py*
-rwxr-xr-x 1 root staff      84 Aug 28 11:29 pydoc
lrwxrwxrwx 1 root staff       9 Aug 28 13:54 python2 -> python2.7
-rwxr-xr-x 1 root staff 5325165 Aug 28 11:56 python2.6
-rwxr-xr-x 1 root staff    1424 Aug 28 11:56 python2.6-config
-rwxr-xr-x 1 root staff 5787340 Aug 28 13:54 python2.7
-rwxr-xr-x 1 root staff    1674 Aug 28 13:54 python2.7-config
lrwxrwxrwx 1 root staff      16 Aug 28 13:54 python2-config -> python2.7-config
lrwxrwxrwx 1 root staff      31 Aug 28 15:49 python-config -> /usr/local/bin/python2.6-config

环境输出:

DM_CONTROL=/var/run/xdmctl
SHELL=/bin/bash
TERM=xterm
XDM_MANAGED=method=classic
DERBY_HOME=/usr/lib/jvm/java-7-oracle/db
OLDPWD=/mnt/extHDD/apps/mpv-build
GTK_MODULES=canberra-gtk-module
USER=root
LS_COLORS=*.c=0;36:*.h=0;33:*.py=0;35:*.exp=0;34
MAIL=/var/mail/root
PATH=/usr/sbin:/usr/bin:/sbin:/bin
DESKTOP_SESSION=default
PWD=/usr/local/bin
JAVA_HOME=/usr/lib/jvm/java-7-oracle
LANG=en_GB.UTF-8
PS1=${debian_chroot:+($debian_chroot)}\u@\h:\w\$ 
HISTIGNORE=&:??:[ ]*:ls:clear:exit:logout
HISTCONTROL=ignoredups
SHLVL=2
HOME=/root
LANGUAGE=en_GB:en
LOGNAME=root
J2SDKDIR=/usr/lib/jvm/java-7-oracle
WINDOWPATH=7
DISPLAY=:0.0
J2REDIR=/usr/lib/jvm/java-7-oracle/jre
_=/usr/bin/env

编辑:根据要求,将 apt_pkg 导入 2.6/2.7 的结果

root@lebowski:/usr/local/bin# /usr/bin/python2.6
Python 2.6.9 (unknown, Aug 28 2014, 11:55:43) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import apt_pkg
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named apt_pkg
>>> 


root@lebowski:/usr/local/bin# /usr/bin/python2.7
Python 2.7.6 (default, Aug 28 2014, 13:52:26) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import apt_pkg
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named apt_pkg
>>> 

相关内容