无法重新安装 python2.6

无法重新安装 python2.6

我正在尝试在 Debian 6 上重新安装 python2.6,但是出现以下问题:

root@ff: apt-get install --reinstall python2.6
Reading package lists... Done
Building dependency tree       
Reading state information... Done
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
 python-pkg-resources : Depends: python (< 2.7) but 2.7.5-5 is to be installed
 python-setuptools : Depends: python (< 2.7) but 2.7.5-5 is to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

请注意,启动 python2.6 可以正常工作:

:~$ python2.6
Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

但是我需要使用的依赖于 python 的应用程序现在已损坏,例如 pip:

~$ pip
Traceback (most recent call last):
  File "/usr/bin/pip", line 7, in <module>
    from pip.log import logger
ImportError: No module named pip.log

我之前安装了 python2.7 并且使用过:

更新替代方案——配置python

切换回 2.6。但似乎使用 python 2.6 安装的应用程序已被 2.7 安装破坏。

我尝试卸载 python2.7。但它说它没有安装,尽管我可以从终端启动它:

# apt-get purge python2.7
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package python2.7 is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 460 not upgraded.
# python
Python 2.7.6 (default, Jan 11 2014, 14:34:26) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

似乎需要完全重新安装系统,但如果可能的话,我想避免这样做。

并且还尝试恢复旧的状态文件:

# cp /var/backups/dpkg.status.2  /var/lib/dpkg/status
# apt-get clean
# apt-get update

我的 /etc/apt/sources 列表:

# deb cdrom:[Debian GNU/Linux 6.0.4 _Squeeze_ - Official amd64 NETINST Binary-1 20120129-00:39]/ squeeze main

#deb cdrom:[Debian GNU/Linux 6.0.4 _Squeeze_ - Official amd64 NETINST Binary-1 20120129-00:39]/ squeeze main

deb http://ftp.se.debian.org/debian/ squeeze main
deb-src http://ftp.se.debian.org/debian/ squeeze main

deb http://security.debian.org/ squeeze/updates main
deb-src http://security.debian.org/ squeeze/updates main

# squeeze-updates, previously known as 'volatile'
deb http://ftp.se.debian.org/debian/ squeeze-updates main
deb-src http://ftp.se.debian.org/debian/ squeeze-updates main
deb http://mirror.cse.iitk.ac.in/debian/ testing main contrib

现在我尝试安装 python-twisted 我得到:

# apt-get install python-twisted
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  iso-codes libserf-0-0 python-apt-common lsb-release
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  cpp-4.4 g++-4.4 gcc-4.4 gcc-4.4-base gcc-4.8-base libapr1 libapr1-dev libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-dev libaprutil1-ldap libc-dev-bin libc6
  libc6-dbg libc6-dev libc6-i386 libdb5.1 libexpat1 libexpat1-dev libffi6 libgcc1 libgmp10 libgomp1 liblzma5 libmpfr4 libpython-dev libpython-stdlib
  libpython2.7 libpython2.7-dev libpython2.7-minimal libpython2.7-stdlib libsasl2-2 libsasl2-modules libsasl2-modules-db libsctp-dev libsctp1 libserf-1-1
  libsqlite3-0 libsqlite3-dev libssl1.0.0 libstdc++6 libstdc++6-4.4-dev libsvn1 libtinfo5 libxml2 linux-headers-2.6.32-5-common locales make multiarch-support
  python python-crypto python-dev python-libxml2 python-lxml python-minimal python-openssl python-pkg-resources python-setuptools python-sqlite python-support
  python-svn python-twisted-bin python-twisted-conch python-twisted-core python-twisted-lore python-twisted-mail python-twisted-names python-twisted-news
  python-twisted-runner python-twisted-web python-twisted-words python-yaml python-zope.interface python2.7 python2.7-dev python2.7-minimal subversion

上面的列表包含一堆 python2.7 依赖项....它们来自哪里? 难道不能为 python2.6 安装 python-twisted 吗?

答案1

这是将 python2.7 安装到 Debian 机器上的极其糟糕的方法,因为 2.6 是该操作系统的默认版本。您很可能会破坏依赖于 /usr/bin/python 的脚本,这些脚本指向该版本中定义和测试过的 python 版本。此外,由于您安装 2.7 的方式,您最终还升级了一些系统库,而 2.6 版本依赖于这些系统库。此时,很难恢复系统。

如果您想在不破坏操作系统的情况下安装 2.7,请从源代码安装并使用 virtualenv。Google 了解相关步骤。

答案2

您安装了错误的 Python 2.7 软件包。除非您清楚自己在做什么,否则不能混合使用不同版本的软件包(这里是 squeeze 和 wheezy)。您可以选择从 wheezy 中完全删除 Python 2.7 软件包,然后最终重新安装 Python 2.6 来修复它;或者将整个系统升级到 wheezy 并删除 Python 2.6。请注意,无论如何,Python 2.7 不应该存在任何兼容性问题。

当然,您也可以从源代码安装,或者创建虚拟环境或 chroot,正如 Danila 所说,但这些都是相当复杂的工作,我不建议经验丰富的系统管理员这样做。如果您想这样做,当然绝对有必要先在测试系统上尝试一下,然后只有在充分理解流程后才能将其部署到生产中。

相关内容