ubuntu安装python-dev,首先需要的是换源,换成国内的源
cd /etc/apt/
cp sources.list source.list.bak
vim sources.list
修改为如下的源:
deb http://mirrors.aliyun.com/ubuntu/ trusty main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main multiverse restricted universe
然后在安装过程中会出现依赖问题:
方法一:
使用aptitude解决问题:
- 1.安装 aptitude
sudo apt-get install aptitude
- 2.然后用aptitude安装python-dev
sudo aptitude install python-dev
然后在出现的选择中依次选择 n , y , y ,这样会自动解决依赖问题,可以升级或者降级需要的版本。
方法二:
使用pyenv,可以安装多版本的python
- 1.安装 pyenv
curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash
- 2.安装完成后,根据提示将如下语句加入到 ~/.bashrc 中:
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)" # 这句可以不加
然后重启终端即可。
查看可安装的版本
$ pyenv install --list
安装对应的版本
$ pyenv install 2.7.5 -v
方法三
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
sudo apt-get install python-dev