1. 程式人生 > >Python之——解決Kali安裝python-dev時依賴出錯的問題

Python之——解決Kali安裝python-dev時依賴出錯的問題

轉載請註明出處:https://blog.csdn.net/l1028386804/article/details/83120113

一、問題現象

在Kali下寫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  

二、問題原因

出現這個問題的原因主要是預設情況下,Kali為python2.7-dev提供的軟體源與python-2.7 2.7.3-0Kali3.1的源不一致,需要更新軟體源。

三、問題解決

可以使用命令apt-cache show python2.7檢視到你安裝python-2.7 2.7.3-0Kali3.1是從源precise-updates/main安裝的,而python2.7-dev預設是從源precise/main安裝的,因此安裝python2.7-dev之前需要更新軟體源。
使用如下的程式碼可以安裝成功

1、更新映象源

vim /etc/apt/sources.list
deb http://mirrors.ustc.edu.cn/kali kali main non-free contrib
deb-src http://mirrors.ustc.edu.cn/kali kali main non-free contrib
deb http://mirrors.ustc.edu.cn/kali-security kali/updates main contrib non-free
apt-get update

2、安裝Python依賴

sudo apt-get update  
sudo apt-get install python2.7-dev
sudo apt-get install python-dev