修复python设置


13

在我的Kubuntu 14.4(标准为python 2.7.6)上,我在python.org上借助如何分别在Debian上安装最新的Python版本或从python.org构建源代码后尝试安装python 2.7.10之后,python断开了升级?。我无法使用标准命令来修复它,我怀疑我的dpkg关于python安装感到困惑/中断。我想在这方面修复dpkg。我怀疑这事做与文件/var/lib/dpkg/status/var/lib/dpkg/available/var/lib/dpkg/info/*particularily第一。我认为我必须以dpkg某种方式重设,但我确实不是专家。我认为这是因为:

$ apt-cache policy python
python:
  Installed: 2.7.10-1
  Candidate: 2.7.10-1
  Version table:
*** 2.7.10-1 0
    100 /var/lib/dpkg/status
2.7.5-5ubuntu3 0
    500 http://de.archive.ubuntu.com/ubuntu/ trusty/main amd64 Packages

$ /usr/bin/python2.7
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

我尝试安装python 2.7.10原因是因为我需要另一个程序(由于python 2.7.6的ssl / openssl问题),但是现在我只想修复我的系统-就让它成为python 2.7 .6。


完整的技术

我开始尝试通过在ubuntu上询问来解决此问题/ubuntu/648424/muon-is-gone-after-change-of-python-issues-after-python-2-7-10-installation-继续,但我没有得到任何答案。也许是错误的人群。从那时起,我已经尝试了很多,并知道出了什么问题,但不知道实现此目标的步骤。

它始于我无法使用安装muon sudo apg-get install muon

$ sudo apt-get install muon
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 muon : Depends: apt-xapian-index but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

典型的建议(例如,来自/ubuntu/118749/package-system-is-broken-how-to-fix-it)没有帮助:

sudo apt-get autoremove
sudo apt-get clean
sudo apt-get autoclean
sudo apt-get update
sudo apt-get upgrade -f
sudo apt-get -f install muon

要么

sudo apt-get -f install

要么

sudo dpkg --configure -a 
sudo apt-get update && sudo apt-get dist-upgrade
sudo apt-get install muon

要么

sudo apt-get -o dpkg::options::="--force-confnew" -o dpkg::options::="--force-confmiss" --reinstall install muon

没有帮助。所以我尝试了

$ sudo apt-get install apt-xapian-index
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 apt-xapian-index : Depends: python-xapian (>= 1.0.2) but it is not going to be installed
                    Depends: python-apt (>= 0.7.93.2) but it is not going to be installed
                    Depends: python-debian (>= 0.1.14) but it is not going to be installed
                    Depends: python:any (>= 2.7.1-0ubuntu2)
E: Unable to correct problems, you have held broken packages.

并发现问题出在其他程序上

$ sudo apt-get install meld 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 meld : Depends: python:any (>= 2.7.1-0ubuntu2)
        Depends: python-gtk2 (>= 2.14) but it is not going to be installed
        Depends: python-glade2 (>= 2.14) but it is not going to be installed
        Depends: python-gobject-2 (>= 2.16) but it is not going to be installed
        Recommends: python-gnome2 but it is not going to be installed
        Recommends: python-gconf but it is not going to be installed
        Recommends: python-gtksourceview2 (>= 2.4) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

所以我尝试了(没有运气)

$ sudo update-alternatives --config python
update-alternatives: error: no alternatives for python

以下内容也无济于事:

sudo dpkg -P python2.7
sudo apt-get install python2.7
sudo dpkg -P python-minimal
sudo apt-get autoremove && sudo apt-get clean sudo apt-get update && sudo apt-get -f install

我正进入(状态

$ apt-cache policy python
python:
  Installed: 2.7.10-1
  Candidate: 2.7.10-1
  Version table:
*** 2.7.10-1 0
    100 /var/lib/dpkg/status
2.7.5-5ubuntu3 0
    500 http://de.archive.ubuntu.com/ubuntu/ trusty/main amd64 Packages

尝试重新安装python不起作用

$ sudo apt-get -o dpkg::options::="--force-confnew" -o dpkg::options::="--force-confmiss" --reinstall install python
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Reinstallation of python is not possible, it cannot be downloaded.
0 upgraded, 0 newly installed, 0 to remove and 16 not upgraded.

要么

$ sudo apt-get -o dpkg::options::="--force-confnew" -o dpkg::options::="--force-confmiss" --reinstall install python2
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package python2

并且尝试构建卸载程序也不起作用:

~/Python-2.7.10$ sudo make uninstall 
make: *** No rule to make target `uninstall'.  Stop.

所以我开始怀疑我必须以某种方式修复dpkg,因为

$ apt-cache policy python
python:
  Installed: 2.7.10-1
  Candidate: 2.7.10-1
  Version table:
*** 2.7.10-1 0
    100 /var/lib/dpkg/status
2.7.5-5ubuntu3 0
    500 http://de.archive.ubuntu.com/ubuntu/ trusty/main amd64 Packages

$ /usr/bin/python2.7
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

更多信息(附录)

$ dpkg -l python* | grep -v ^un
Gewünscht=Unbekannt/Installieren/R=Entfernen/P=Vollständig Löschen/Halten
| Status=Nicht/Installiert/Config/U=Entpackt/halb konFiguriert/
    Halb installiert/Trigger erWartet/Trigger anhängig
|/ Fehler?=(kein)/R=Neuinstallation notwendig (Status, Fehler: GROSS=schlecht)
||/ Name                                        Version                                 Architektur  Beschreibung
+++-===========================================-=======================================-============-=====================================================================================================================================================================================================================
ii  python                                      2.7.10-1                                amd64        Python 2.7.10
ii  python-apt-common                           0.9.3.5ubuntu1                          all          Python interface to libapt-pkg (locales)
ii  python-chardet-whl                          2.2.1-2~ubuntu1                         all          universal character encoding detector
ii  python-colorama-whl                         0.2.5-0.1ubuntu2                        all          Cross-platform colored terminal text in Python - Wheels
ii  python-cups                                 1.9.66-0ubuntu2                         amd64        Python bindings for CUPS
rc  python-cupshelpers                          1.4.3+20140219-0ubuntu2.6               all          Python modules for printer configuration with CUPS
ii  python-dbus-dev                             1.2.0-2build2                           all          main loop integration development files for python-dbus
ii  python-distlib-whl                          0.1.8-1ubuntu1                          all          low-level components of python distutils2/packaging
rc  python-gobject-2                            2.28.6-12build1                         amd64        deprecated static Python bindings for the GObject library
ii  python-html5lib-whl                         0.999-3~ubuntu1                         all          HTML parser/tokenizer based on the WHATWG HTML5 specification
ii  python-ldb                                  1:1.1.16-1                              amd64        Python bindings for LDB
ii  python-minimal                              2.7.5-5ubuntu3                          amd64        minimal subset of the Python language (default version)
ii  python-ntdb                                 1.0-2ubuntu1                            amd64        Python bindings for NTDB
ii  python-pam                                  0.4.2-13.1ubuntu3                       amd64        Python interface to the PAM library
ii  python-pip-whl                              1.5.4-1ubuntu3                          all          alternative Python package installer
ii  python-renderpm                             3.0-1build1                             amd64        python low level render interface
ii  python-reportlab-accel                      3.0-1build1                             amd64        C coded extension accelerator for the ReportLab Toolkit
ii  python-requests-whl                         2.2.1-1ubuntu0.3                        all          elegant and simple HTTP library for Python, built for human beings
ii  python-setuptools-whl                       3.3-1ubuntu2                            all          Python Distutils Enhancements (wheel package)
ii  python-six-whl                              1.5.2-1ubuntu1                          all          Python 2 and 3 compatibility library (universal wheel)                                               
rc  python-support                              1.0.15                                  all          automated rebuilding support for Python modules                                                      
ii  python-talloc                               2.1.0-1                                 amd64        hierarchical pool based memory allocator - Python bindings                                           
ii  python-tdb                                  1.2.12-1                                amd64        Python bindings for TDB                                                                              
ii  python-twisted-bin                          13.2.0-1ubuntu1                         amd64        Event-based framework for internet applications                                                      
rc  python-twisted-core                         13.2.0-1ubuntu1                         all          Event-based framework for internet applications                                                      
rc  python-ubuntu-sso-client                    13.10-0ubuntu6                          all          Ubuntu Single Sign-On client - Python library                                                        
ii  python-urllib3-whl                          1.7.1-1ubuntu3                          all          HTTP library with thread-safe connection pooling                                                     
ii  python2.7                                   2.7.6-8ubuntu0.2                        amd64        Interactive high-level object-oriented language (version 2.7)                                        
ii  python2.7-minimal                           2.7.6-8ubuntu0.2                        amd64        Minimal subset of the Python language (version 2.7)                                                  
ii  python3                                     3.4.0-0ubuntu2                          amd64        interactive high-level object-oriented language (default python3 version)                            
ii  python3-apport                              2.14.1-0ubuntu3.11                      all          Python 3 library for Apport crash report handling                                                    
ii  python3-apt                                 0.9.3.5ubuntu1                          amd64        Python 3 interface to libapt-pkg                                                                     
ii  python3-aptdaemon                           1.1.1-1ubuntu5.2                        all          Python 3 module for the server and client of aptdaemon                                               
ii  python3-chardet                             2.2.1-2~ubuntu1                         all          universal character encoding detector for Python3                                                    
ii  python3-colorama                            0.2.5-0.1ubuntu2                        all          Cross-platform colored terminal text in Python - Python 3.x                                          
ii  python3-commandnotfound                     0.3ubuntu12                             all          Python 3 bindings for command-not-found.                                                             
ii  python3-dbus                                1.2.0-2build2                           amd64        simple interprocess messaging system (Python 3 interface)                                            
ii  python3-dbus.mainloop.qt                    4.10.4+dfsg-1ubuntu1                    amd64        D-Bus Support for PyQt4 with Python 3
ii  python3-debian                              0.1.21+nmu2ubuntu2                      all          Python 3 modules to work with Debian-related data formats
ii  python3-defer                               1.0.6-2build1                           all          Small framework for asynchronous programming (Python 3)
ii  python3-dev                                 3.4.0-0ubuntu2                          amd64        header files and a static library for Python (default)
ii  python3-distlib                             0.1.8-1ubuntu1                          all          low-level components of python distutils2/packaging
ii  python3-distupgrade                         1:0.220.7                               all          manage release upgrades
ii  python3-gdbm:amd64                          3.4.0-0ubuntu1                          amd64        GNU dbm database support for Python 3.x
ii  python3-gi                                  3.12.0-1ubuntu1                         amd64        Python 3 bindings for gobject-introspection libraries
ii  python3-html5lib                            0.999-3~ubuntu1                         all          HTML parser/tokenizer based on the WHATWG HTML5 specification (Python 3)
ii  python3-minimal                             3.4.0-0ubuntu2                          amd64        minimal subset of the Python language (default python3 version)
ii  python3-pip                                 1.5.4-1ubuntu3                          all          alternative Python package installer - Python 3 version of the package
ii  python3-pkg-resources                       3.3-1ubuntu2                            all          Package Discovery and Resource Access using pkg_resources
ii  python3-problem-report                      2.14.1-0ubuntu3.11                      all          Python 3 library to handle problem reports
ii  python3-pycurl                              7.19.3-0ubuntu3                         amd64        Python 3 bindings to libcurl
ii  python3-pykde4                              4:4.13.3-0ubuntu0.1                     amd64        Python 3 bindings for the KDE Development Platform
ii  python3-pyqt4                               4.10.4+dfsg-1ubuntu1                    amd64        Python3 bindings for Qt4
ii  python3-requests                            2.2.1-1ubuntu0.3                        all          elegant and simple HTTP library for Python3, built for human beings
ii  python3-setuptools                          3.3-1ubuntu2                            all          Python3 Distutils Enhancements
ii  python3-sip                                 4.15.5-1build1                          amd64        Python 3/C++ bindings generator runtime library
ii  python3-six                                 1.5.2-1ubuntu1                          all          Python 2 and 3 compatibility library (Python 3 interface)
ii  python3-software-properties                 0.92.37.3                               all          manage the repositories that you install software from
ii  python3-uno                                 1:4.2.8-0ubuntu2                        amd64        Python-UNO bridge
ii  python3-update-manager                      1:0.196.13                              all          python 3.x module for update-manager
ii  python3-urllib3                             1.7.1-1ubuntu3                          all          HTTP library with thread-safe connection pooling for Python3
ii  python3-wheel                               0.24.0-1~ubuntu1                        all          built-package format for Python
ii  python3-xkit                                0.5.0ubuntu2                            all          library for the manipulation of xorg.conf files (Python 3)
ii  python3.4                                   3.4.0-2ubuntu1.1                        amd64        Interactive high-level object-oriented language (version 3.4)
ii  python3.4-dev                               3.4.0-2ubuntu1.1                        amd64        Header files and a static library for Python (v3.4)
ii  python3.4-minimal                           3.4.0-2ubuntu1.1                        amd64        Minimal subset of the Python language (version 3.4)

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.2 LTS
Release:        14.04
Codename:       trusty

$ grep -P '^[ \t]*[^#[ \t]+' /etc/apt/sources.list /etc/apt/sources.list.d/*.list
/etc/apt/sources.list:deb http://de.archive.ubuntu.com/ubuntu/ trusty main restricted
/etc/apt/sources.list:deb-src http://de.archive.ubuntu.com/ubuntu/ trusty main restricted
/etc/apt/sources.list:deb http://de.archive.ubuntu.com/ubuntu/ trusty-updates main restricted
/etc/apt/sources.list:deb-src http://de.archive.ubuntu.com/ubuntu/ trusty-updates main restricted
/etc/apt/sources.list:deb http://de.archive.ubuntu.com/ubuntu/ trusty universe
/etc/apt/sources.list:deb-src http://de.archive.ubuntu.com/ubuntu/ trusty universe
/etc/apt/sources.list:deb http://de.archive.ubuntu.com/ubuntu/ trusty-updates universe
/etc/apt/sources.list:deb-src http://de.archive.ubuntu.com/ubuntu/ trusty-updates universe
/etc/apt/sources.list:deb http://de.archive.ubuntu.com/ubuntu/ trusty multiverse
/etc/apt/sources.list:deb-src http://de.archive.ubuntu.com/ubuntu/ trusty multiverse
/etc/apt/sources.list:deb http://de.archive.ubuntu.com/ubuntu/ trusty-updates multiverse
/etc/apt/sources.list:deb-src http://de.archive.ubuntu.com/ubuntu/ trusty-updates multiverse
/etc/apt/sources.list:deb http://de.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
/etc/apt/sources.list:deb-src http://de.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
/etc/apt/sources.list:deb http://security.ubuntu.com/ubuntu trusty-security main restricted
/etc/apt/sources.list:deb-src http://security.ubuntu.com/ubuntu trusty-security main restricted
/etc/apt/sources.list:deb http://security.ubuntu.com/ubuntu trusty-security universe
/etc/apt/sources.list:deb-src http://security.ubuntu.com/ubuntu trusty-security universe
/etc/apt/sources.list:deb http://security.ubuntu.com/ubuntu trusty-security multiverse
/etc/apt/sources.list:deb-src http://security.ubuntu.com/ubuntu trusty-security multiverse
/etc/apt/sources.list:deb http://archive.canonical.com/ubuntu trusty partner
/etc/apt/sources.list:deb http://extras.ubuntu.com/ubuntu trusty main
/etc/apt/sources.list:deb http://cran.uni-muenster.de/bin/linux/ubuntu trusty/
/etc/apt/sources.list.d/fossfreedom-packagefixes-trusty.list:deb http://ppa.launchpad.net/fossfreedom/packagefixes/ubuntu trusty main
/etc/apt/sources.list.d/jitsi.list:deb http://download.jitsi.org/deb unstable/
/etc/apt/sources.list.d/leviatan1-ppa-trusty.list:deb http://ppa.launchpad.net/leviatan1/ppa/ubuntu trusty main

$ whereis python
python: /usr/bin/python /usr/bin/python3.4-config /usr/bin/python3.4 /usr/bin/python3.4m /usr/bin/python2.7 /usr/bin/python3.4m-config /etc/python /etc/python3.4 /etc/python2.7 /usr/lib/python3.4 /usr/lib/python2.7 /usr/bin/X11/python /usr/bin/X11/python3.4-config /usr/bin/X11/python3.4 /usr/bin/X11/python3.4m /usr/bin/X11/python2.7 /usr/bin/X11/python3.4m-config /usr/local/lib/python3.4 /usr/local/lib/python2.7 /usr/include/python3.4 /usr/include/python3.4m /usr/share/python /usr/share/man/man1/python.1.gz

$ whereis python2.7
python2: /usr/bin/python2.7 /usr/bin/python2 /etc/python2.7 /usr/lib/python2.7 /usr/bin/X11/python2.7 /usr/bin/X11/python2 /usr/local/lib/python2.7 /usr/share/man/man1/python2.1.gz

whereis python2.7和的输出是whereis python什么?
2015年

下次您要从源代码编译和安装Python时,最好将其安装到其他位置(第一个)。Python在您的系统中作为其他应用程序使用的软件堆栈的一部分存在。如果不进行测试就安装整个系统的Python安装会有些危险。您可以设置通过提供安装位置--prefix=/path/to/folder./configure命令。
本杰明·B。

@Wilf我将信息添加到附录中。
2015年

@BenjaminB。您能提供完整的命令来详细说明吗?什么./configure命令?(我还没有编程/使用python)。
Make42

如果您按照说明对所发布的另一个堆栈交换问题进行了操作,那么您有时就已运行./configure --prefix=/opt/python。如果您不这样做,这可能是出问题的地方。如果不提供--prefix=/opt/python零件,则可能会覆盖系统范围的安装。您是否完全遵循了这些指示?
本杰明·B.

Answers:


20

您安装的Python软件包比发行版提供的软件包要新。例如,您python安装了2.7.10-1版,但是您的发行版中只有2.7.5-5ubuntu3版。

除非明确指示,否则APT不会降级软件包。因此,例如,如果您尝试安装依赖于Python确切版本的python软件包,则该软件包将无法工作,因为该软件包无法降级。甚至apt-get --reinstall install python失败,因为APT不会将Python降级到2.7.5。

为了修复您的系统,您需要允许APT执行降级。为此,请定义APT首选项。创建一个/etc/apt/preferences.d/allow-downgrade包含以下内容的文件

Package: *
Pin: release o=Ubuntu
Pin-Priority: 1001

/etc/apt/preferences.d(加号/etc/apt/preferences)中的文件包含优先级声明,这些优先级声明在有多个版本的软件包可用时会覆盖默认选择,即“首选目标发行版中的最新版本”。为软件包提供超过1000的优先级将使其成为首选,即使它是较旧版本的优先级较低的软件包。已安装的软件包的优先级为500,因此来自Ubuntu的软件包将获胜。有关更多信息,请参见:

man apt_preferences

我认为,一旦您设置了这些优先级,便可以运行

apt-get update
apt-get upgrade

将所有软件包降级到Ubuntu中的版本(不在Ubuntu中的软件包将不会被删除)。还要运行apt-get -f install,在此操作成功完成之前,请不要尝试安装任何其他软件。

一切降级后,请删除首选项文件并apt-get update再次运行。


1
您是否知道一个很好的资源,可以通过apt等阅读有关此主题的更多信息?(或者换句话说:您怎么知道的?)
Make42

1
@ user49283嗯,unix.stackexchange.com / tags / apt和Debian Wiki(答案链接)?对不起,这是根据经验。
吉尔斯(Gillles)“所以-别再邪恶了”

@ Make42 man apt_preferences
Faheem Mitha

0

我发现只有一种方法起作用了。

  1. 步骤1:从此处下载python 2.7 deb软件包并安装

    sudo dpkg -i <package-name>
  2. 使用dbkg工具列出与python相关的所有内容

    sudo dpkg -l | grep python
  3. 删除上面找到的所有内容

    sudo dpkg --purge --force-all软件包名称

  4. 试着做

    sudo apt upgrade

它将在最后给出损坏的软件包列表。使用步骤3删除它们

  1. 重复步骤3-4,直到sudo apt upgrade不给出任何错误

  2. 您可能需要使用作为deb软件包安装的python 2.7的位置来创建到/ usr / bin / python的符号链接。(locate bin/python)和ln -s <path> /usr/bin/python

  3. 此时,python应该已修复。但是请执行发行升级(有关如何更新到最新的ubuntu而非LTS的信息,请阅读手册)

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.