• jenkins2—进docker容器安装python3环境


    前言

    使用docker安装jenkins环境,jenkins构建的workspace目录默认是在容器里面构建的,如果我们想执行python3的代码,需进容器内安装python3的环境;

    进jenkins容器

    进docker容器,加上 -u root 以root用户权限进入容器

    docker exec -it -u root 容器name /bin/bash
    

     查看当前操作系统 cat /etc/issue;

    root@86723e0cd5bb:/# uname -a
    Linux 86723e0cd5bb 3.10.0-1062.9.1.el7.x86_64 #1 SMP Fri Dec 6 15:49:49 UTC 2019 x86_64 GNU/Linux
    root@86723e0cd5bb:/# cat /etc/issue
    Debian GNU/Linux 9 
     l
    

     这里查到的是Debian系统(不是ubuntu,也不是centos),这里yum是没有的,所以不能用yum安装了,这里用apt-get代替yum

    先执行更新apt-get

    apt-get update
    

     容器内部安装python3环境

     下载python3安装包

    进入容器内容,linux安装python3环境

    root@cb8e397d5308:/var/jenkins_home# cd /var/jenkins_home/
    root@cb8e397d5308:/var/jenkins_home# mkdir python3
    root@cb8e397d5308:/var/jenkins_home# cd python3/
    root@cb8e397d5308:/var/jenkins_home/python3# wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz
    root@cb8e397d5308:/var/jenkins_home/python3# tar -xvf Python-3.6.8.tgz
    root@cb8e397d5308:/var/jenkins_home/python3# ls
    Python-3.6.8  Python-3.6.8.tgz
    root@cb8e397d5308:/var/jenkins_home/python3# cd Python-3.6.8
    root@cb8e397d5308:/var/jenkins_home/python3/Python-3.6.8# ./configure --prefix=/var/jenkins_home/python3
    checking build system type... x86_64-pc-linux-gnu
    checking host system type... x86_64-pc-linux-gnu
    checking for python3.6... no
    checking for python3... no
    checking for python... python
    checking for --enable-universalsdk... no
    checking for --with-universal-archs... no
    checking MACHDEP... linux
    checking for --without-gcc... no
    checking for --with-icc... no
    checking for gcc... no
    checking for cc... no
    checking for cl.exe... no
    configure: error: in `/var/jenkins_home/python3/Python-3.6.8':
    configure: error: no acceptable C compiler found in $PATH
    See `config.log' for more details
    

     执行 ./configure --prefix=/var/jenkins_home/python3时报上面错:configure: error: no acceptable C compiler found in $PATH  

    apt-get 安装依赖包

    这个是因为缺少gcc相关依赖包,使用apt-get代替yum安装相关依赖包

    apt-get -y install gcc automake autoconf libtool make
    apt-get -y install make*
    apt-get -y install zlib*
    apt-get -y install openssl libssl-dev
    apt-get install sudo
    

     make编译安装

    在/var/jenkins_home/python3/Python-3.6.8目录下执行make和make install安装

    ./configure --prefix=/var/jenkins_home/python3 --with-ssl
    make
    make install
    

     注意:上面加--with--ssl参数,此时不加该参数,后面pip安装可以报ssl相关问题; 

    添加软链接

     添加python3软链接

    ln -s /var/jenkins_home/python3/bin/python3.6 /usr/bin/python3
    

      添加pip3软链接

    ln -s /var/jenkins_home/python3/bin/pip3 /usr/bin/pip3
    

     检查环境

    输入pip3和python3检查环境

    root@cb8e397d5308:/var/jenkins_home/python3/Python-3.6.8# pip3
    
    root@cb8e397d5308:/var/jenkins_home/python3/Python-3.6.8# python3
    Python 3.6.8 (default, Jan  1 2020, 10:15:14) 
    [GCC 6.3.0 20170516] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> exit()
    

     使用pip3安装一个requests包

    pip3 install requests
    

      

    越努力,越幸运!!! good good study,day day up!!!
  • 相关阅读:
    647. 回文子串
    109. 有序链表转换二叉搜索树
    第1篇 第1章 走进推荐系统
    推荐系统为什么要分测试集与训练集
    面向对象案例 烤地瓜 搬家具python实现
    python面向对象方法
    python实现学生信息系统
    随机数据的生成
    Python中numpy的应用
    pandas 的index用途
  • 原文地址:https://www.cnblogs.com/canglongdao/p/14071610.html
Copyright © 2020-2023  润新知