美文网首页
内网linux主机部署python运行环境

内网linux主机部署python运行环境

作者: A04 | 来源:发表于2019-08-05 19:32 被阅读0次

        一台内网linux主机需要部署python运行环境,linux主机是CentOS7,需要使用python3.6.4。

    1、下载python、解压

        python官网找到并下载python3.6.4版本的linux安装包Python-3.6.4.tgz。一开始通过winscp上传到linux主机上,解压该压缩文件,出现报错。

    [root@localhost hhh]# tar -zxvf Python-3.6.4.tgz 
    
    ……
    
    gzip: stdin: invalid compressed data--format violated
    tar: Child returned status 1
    tar: Error is not recoverable: exiting now
    [root@localhost hhh]# ls
    

        百度,最后发现是通过winscp上传的时候,文件传输模式是ascii,导致压缩包损坏,需要使用binary方式传输。找不到修改传输模式的地方,于是考虑使用lrzsz,增加参数-b,就是使用binary,如果使用参数-a,就是使用ascii模式;顺利完成文件传输并完成解压

    [root@localhost hhh]# mkdir b
    [root@localhost hhh]# cd b
    [root@localhost b]# rz -b 
    
    [root@localhost b]# ls
    Python-3.6.4.tgz
    [root@localhost b]# ll
    total 22180
    -rw-r--r--. 1 root root 22710891 Aug  5 05:40 Python-3.6.4.tgz
    [root@localhost b]# tar -zxf Python-3.6.4.tgz 
    [root@localhost b]# ls
    Python-3.6.4  Python-3.6.4.tgz
    [root@localhost b]# cd Python-3.6.4/
    [root@localhost Python-3.6.4]# ls
    aclocal.m4    config.sub  configure.ac  Grammar  install-sh  LICENSE  Makefile.pre.in  Modules  Parser  PCbuild   pyconfig.h.in  README.rst  Tools
    config.guess  configure   Doc           Include  Lib         Mac      Misc             Objects  PC      Programs  Python         setup.py
    [root@localhost Python-3.6.4]#
    

    2、安装python

        安装过程比较顺利,按照以下命令执行即可

    [root@localhost Python-3.6.4]# ./configure
    [root@localhost Python-3.6.4]# make
    [root@localhost Python-3.6.4]# sudo make install
    [root@localhost Python-3.6.4]# python
    python             python2            python2.7          python2.7-config   python2-config     python3            python3.6          python3.6-config   python3.6m         python3.6m-config  python3-config     python-config
    [root@localhost Python-3.6.4]# python3
    Python 3.6.4 (default, Aug  5 2019, 06:16:42) 
    [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 
    

    3、安装zlib、setuptools、pip

        安装python模块一般使用pip,安装pip需要先安装setuptools,下载setuptools-41.4.0.zip。

    unzip setuptools-41.4.0.zip
    python3 setup.py build
    python3 setup.py install
    报错:RuntimeError: Compression requires the (missing) zlib module
    
    下载zlib,http://117.128.6.10/cache/zlib.net/zlib-1.2.11.tar.gz
    tar -zxvf zlib-1.2.11.tar.gz
    cd zlib-1.2.11/
    ./configure
    make
    make install
    
    进入python3安装文件目录,重新编译安装python
    ./configure
    make
    make install
    
    回到setuptools目录
    python3 setup.py install
    
    进入pip安装文件目录,安装pip
    python setup.py install
    
    

    4、安装模块

        需要使用的模块有xlrd,上网站https://pypi.org/下载离线安装包,在该网站搜索xlrd,下载文件xlrd-1.2.0-py2.py3-none-any.whl,安装指令和过程如下:

    
    [root@localhost b]# rz -b 
    
    [root@localhost b]# ls
    Python-3.6.4  Python-3.6.4.tgz  xlrd-1.2.0-py2.py3-none-any.whl
    [root@localhost b]# python3 -m pip install xlrd-1.2.0-py2.py3-none-any.whl 
    Processing ./xlrd-1.2.0-py2.py3-none-any.whl
    Installing collected packages: xlrd
    Successfully installed xlrd-1.2.0
    
    [root@localhost b]# python3
    Python 3.6.4 (default, Aug  5 2019, 06:16:42) 
    [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import xlrd
    >>> 
    
    

    相关文章

      网友评论

          本文标题:内网linux主机部署python运行环境

          本文链接:https://www.haomeiwen.com/subject/hgrvdctx.html