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”
這裏寫圖片描述
3、安裝其它的
yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel
安裝的python退格鍵和箭頭不可以正常使用,會出現”>>> daf ^H^[[D “這樣的怪東西。是因爲readline庫的問題。那麼解決的方法就是:
安裝yum install readline-devel.*
這裏寫圖片描述

4、下載、編譯和安裝 Python 2.7.13

這裏寫圖片描述

 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*
這裏寫圖片描述

/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

這裏寫圖片描述
查看新的 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

這裏寫圖片描述

7、安裝cryptography

pip install cryptography

這裏寫圖片描述

8、安裝paramiko

pip install paramiko

這裏寫圖片描述

9、安裝pexpect

pip install pexpect

這裏寫圖片描述

10、測試,沒有報錯即可

import pexpect
import paramiko

這裏寫圖片描述

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

發佈了125 篇原創文章 · 獲贊 148 · 訪問量 56萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章