Linux安装python2.7 easy_install pip paramiko pexpect

前言
在Centos机器上安装Python模块 paramiko和pexpect包
以后python的模块包都可以通过”pip install模块名” 实现

大环境:
 没有编译器gcc  需要安装开发软件
 yum源没有安装包
 系统是Centos6  需要找到合适的yum源
 自带python版本是2.6  需要升级
 没有安装wget  yum install wget 进行安装
具体操作
1、配置yum源

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#released updates 
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

2、安装所有的开发工具包
yum groupinstall -y “Development tools”
Linux安装python2.7 easy_install pip paramiko pexpect_第1张图片
3、安装其它的
yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel
安装的python退格键和箭头不可以正常使用,会出现”>>> daf ^H^[[D “这样的怪东西。是因为readline库的问题。那么解决的方法就是:
安装yum install readline-devel.*
Linux安装python2.7 easy_install pip paramiko pexpect_第2张图片

4、下载、编译和安装 Python 2.7.13

Linux安装python2.7 easy_install pip paramiko pexpect_第3张图片

 wget https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz
    tar zxf Python-2.7.13.tgz
    cd Python-2.7.13
    ./configure
    make && make install

默认 Python 2.7.13 会安装在 /usr/local/bin 目录下。
ll -tr /usr/local/bin/python*
Linux安装python2.7 easy_install pip paramiko pexpect_第4张图片

/usr/local/bin/python2.7
/usr/local/bin/python2.7-config
/usr/local/bin/python -> python2
/usr/local/bin/python2 -> python2.7
/usr/local/bin/python2-config -> python2.7-config
/usr/local/bin/python-config -> python2-config
而系统自带的 Python 是在 /usr/bin 目录下。
ll -tr /usr/bin/python*
/usr/bin/python2.6-config
/usr/bin/python2.6
/usr/bin/python
/usr/bin/python2 -> python
/usr/bin/python-config -> python2.6-config

更新系统默认 Python 版本
先把系统默认的旧版 Python 重命名。
mv /usr/bin/python /usr/bin/python.old
再删除系统默认的 python-config 软链接。
rm -f /usr/bin/python-config
最后创建新版本的 Python 软链接。
ln -s /usr/local/bin/python /usr/bin/python
ln -s /usr/local/bin/python-config /usr/bin/python-config
ln -s /usr/local/include/python2.7/ /usr/include/python2.7
以上步骤做完以后,目录 /usr/bin 下的 Python 应该是
ll -tr /usr/bin/python*

/usr/bin/python2.6-config
/usr/bin/python2.6
/usr/bin/python.old
/usr/bin/python2 -> python
/usr/bin/python -> /usr/local/bin/python
/usr/bin/python-config -> /usr/local/bin/python-config

Linux安装python2.7 easy_install pip paramiko pexpect_第5张图片
查看新的 Python 版本
python –version
返回 Python 2.7.13 为正常。

5、为新版 Python 安装 setuptools
为新版 Python 安装 setuptools

wget https://bootstrap.pypa.io/ez_setup.py -O - | python

setuptools 正确安装完成后,easy_install 命令就会被安装在 /usr/local/bin 目录下了。

6、安装pip

easy_install  pip

Linux安装python2.7 easy_install pip paramiko pexpect_第6张图片

7、安装cryptography

pip install cryptography

Linux安装python2.7 easy_install pip paramiko pexpect_第7张图片

8、安装paramiko

pip install paramiko

Linux安装python2.7 easy_install pip paramiko pexpect_第8张图片

9、安装pexpect

pip install pexpect

Linux安装python2.7 easy_install pip paramiko pexpect_第9张图片

10、测试,没有报错即可

import pexpect
import paramiko

Linux安装python2.7 easy_install pip paramiko pexpect_第10张图片

参考资料
http://www.cnblogs.com/94YY/p/6224441.html
http://blog.csdn.net/zyz511919766/article/details/18355795
http://huakai201.blog.51cto.com/6156209/1431016

你可能感兴趣的:(python)