一般情况下,linux服务器都处在一个与互联网隔绝的环境里,所以安装python环境及paramiko模块时,需要用源码的方式进行安装。

现将安装过程及注意事项记录如下:

一、安装python3(RedHat升级Python2.6到Python3.6.5版本)

1.升级前的环境信息

  1.1操作系统

  [root@IPM ~]# cat /etc/redhat-release

  Red Hat Enterprise Linux Server release 6.5(Santiago)

  1.2Python版本  

  [root@IPM ~]#  python -V

  Python 2.6.5

2.下面我们将Python进行编译并安装Python3.6.5版本(保留老版本)

  2.1将已经下载好的Python3.6.5源码包通过winscp传输到linux服务器上,放在root用户文件夹下的Download文件夹中

  2.2进入Download文件夹对Python3.6.5源码包进行解压

    [root@IPM Download]#tar -xzvf Python-3.6.5.tgz

  2.3进入Python3.6.5文件夹,进行编译安装操作

    [root@IPM Download]#cd Python-3.6.5

    [root@IPM Python-3.6.5]#mkdir /usr/local/python3.6.5

    [root@IPM Python-3.6.5]#./configure –prefix=/usr/local/python3.6.5        ***配置安装Python文件的目录

    [root@IPM Python-3.6.5]#make  && make install

  2.4备份老版本,删除旧链接并重新创建链接

    #备份python旧版本信息

    [root@IPM Python-3.6.5]#mv /usr/bin/python  /usr/bin/python2.6_old

    [root@IPM Python-3.6.5]#rm /usr/bin/python2

    [root@IPM Python-3.6.5]#ln -s /usr/bin/python2.6_old /usr/bin/python2

3.建立Python3.6.5的环境变量

  [root@IPM Python-3.6.5]#ln -s /usr/local/python3.6.5/bin/python3.6  /usr/bin/python
  [root@IPM ~]#python -V
  Python 3.6.5
 
二、安装paramiko模块装注意事项

解压命令:
  tar –xvf file.tar //解压 tar包
  tar -xzvf file.tar.gz //解压tar.gz
  tar -xjvf file.tar.bz2 //解压 tar.bz2
  tar –xZvf file.tar.Z //解压tar.Z
  unrar e file.rar //解压rar
  unzip file.zip //解压zip

 1.paramiko模块需要依赖模块:

  Cryptography
  asn1crypto
  bcrypt
  certifi-2018
  cffi-1
  chardet
  crypto
  idna-2.6
  libffi
  Naked
  pyasn1
  pycparser
  pycrypto
  PyNaCl
  PyYAML
  requests
  shellescape
  six-1
  urllib3-1

2.安装libffi需要注意以下事项:

  cd libffi-3.2.1

  ./configure && make && make install

 安装libffi模块后,如果在安装paramiko的过程中提示:

  Package libffi was not found in the pkg-config search path. 

  Perhaps you should add the directory containing `libffi.pc’

  to the PKG_CONFIG_PATH environment variable

  No package ‘libffi’ found   

    进行以下操作:

  find /usr/local |grep libffi.pc 命令输出:/usr/local/lib/pkgconfig/libffi.pc

  export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH

 如果还有提示如下: 

        ImportError: libffi.so.6: cannot open shared object file: No such file or directory 

    进行以下操作: 

        export LD_LIBRARY_PATH=/usr/local/lib64      (64位系统) 

 也可以写入环境变量文件中:
  vi /etc/profile
  export LD_LIBRARY_PATH=/usr/local/lib64
  export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH

让/etc/profile文件修改后立即生效
  方法1:
  让/etc/profile文件修改后立即生效 ,可以使用如下命令: 
    # .  /etc/profile 
    注意: . 和 /etc/profile 有空格 
  方法2: 
  让/etc/profile文件修改后立即生效 ,可以使用如下命令: 
    # source /etc/profile 

版权声明:本文为leiaoo原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/leiaoo/p/8677371.html