解决ubuntu12.04安装python-dev时依赖出错的问题

在ubuntu下写python代码的时候,有时会需要安装一些第三方的库,安装的时候却提示:
SystemError: Cannot compile 'Python.h'. Perhaps you need to install python-dev.

然后按照提示sudo apt-get install python-dev又仆街,提示:

The following packages have unmet dependencies:
 python-dev : Depends: python2.7-dev (>= 2.7.3) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

于是我又sudo apt-get install python2.7-dev,显示依赖错误:

The following packages have unmet dependencies:
 python2.7-dev : Depends: python2.7 (= 2.7.3-0ubuntu3) but 2.7.3-0ubuntu3.1 is to be installed
                 Depends: libpython2.7 (= 2.7.3-0ubuntu3) but 2.7.3-0ubuntu3.1 is to be installed

这个问题碰到了两次,第一次在国内的网站上找答案没找到就放弃了,第二次去鬼佬的网站上终于找到了答案。

根据我的理解,出现这个问题的原因主要是默认情况下,ubuntu为python2.7-dev提供的软件源与python-2.7 2.7.3-0ubuntu3.1的源不一值,

需要更新软件源。

可以使用命令apt-cache show python2.7查看到你安装python-2.7 2.7.3-0ubuntu3.1是从源precise-updates/main安装的,而python2.7-dev默认是

从源precise/main安装的,因此安装python2.7-dev之前需要更新软件源。

使用如下的代码我安装成功了,希望有所帮助:

echo "deb http://us.archive.ubuntu.com/ubuntu/ precise-updates main restricted" | sudo tee -a /etc/apt/sources.list.d/precise-updates.list
sudo apt-get update
sudo apt-get install python2.7-dev


如果这样不行的话,你可以自己去鬼佬的网站上看: http://askubuntu.com/questions/275861/problem-installing-python-dev

你可能感兴趣的:(python)