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

在Ubuntu下写python代码的时候,有时会需要安装一些第三方的库,安装的时候提示:

  1. SystemError: Cannot compile 'Python.h'. Perhaps you need to install python-dev.  

然后按照提示sudo apt-get install Python-dev又出错,提示:

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

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

[python]  view plain  copy
  1. The following packages have unmet dependencies:  
  2.  python2.7-dev : Depends: python2.7 (= 2.7.3-0ubuntu3) but 2.7.3-0ubuntu3.1 is to be installed  
  3.                  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之前需要更新软件源。

使用如下的代码可以安装成功:

[python]  view plain  copy
  1. echo "deb http://us.archive.ubuntu.com/ubuntu/ precise-updates main restricted" | sudo tee -a /etc/apt/sources.list.d/precise-updates.list  
  2. sudo apt-get update  
  3. sudo apt-get install python2.7-dev
  4. sudo apt-get install python-dev
如果这样不行的话,可以参考这个网站:http://askubuntu.com/questions/275861/problem-installing-python-dev
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

孙强 Jimmy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值