centos8安装python3.8.19并在python虚拟环境运行程序

一、安装python3.8.19

       1.1 下载python 安装包  

wget https://www.python.org/ftp/python/3.8.19/Python-3.8.19.tgz

        1.2 操作系统安装一些库

yum -y install bzip2 bzip2-devel ncurses openssl openssl-devel openssl-static xz lzma xz-devel sqlite sqlite-devel gdbm gdbm-devel tk tk-devel libffi-devel

## bzip2 在pandas库中用到,如果不安装,使用pandas会报 "No module named '_bz2'",到时候需要重装Python

## openssl 如果不存在,在Python 安装configure 阶段会报错

       1.3 安装python

            configure

# ******* 如果提示找不到openssl,配置指定openssl********
export OPENSSL_LIBS=/usr/lib64/libssl.so

# 执行config,--prefix 指定安装目录

./configure \
  --prefix=/data/yw_int_platform/python3_8 \
  --with-openssl=/usr \
  --enable-optimizations

            make

make -j 8

make时报错:
     ctx = SSL_CTX_new(SSLv3_method());
                           ^~~~~~~~~~~~
                           SSLv23_method

修改python 安装包中的文件,参考:https://gist.github.com/Lh4cKg/fc6f1b6d6e6d285f51d6
修改_ssl.c文件(Python-3.x.x/Modules/_ssl.c)

# instead of
else if (proto_version == PY_SSL_VERSION_SSL3)
        ctx = SSL_CTX_new(SSLv3_method());

# this shoud be
else if (proto_version == PY_SSL_VERSION_SSL23)
        ctx = SSL_CTX_new(SSLv23_method());

修改Setup 文件(Python-3.x.x/Modules/Setup)
# uncommented code: 
_ssl _ssl.c \
       -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
       -L$(SSL)/lib -lssl -lcrypto

重新执行configure

           sudo make altinstall

二、安装python 虚拟环境

        2.1 安装 virtualenv

        2.2 执行 virtualenv -p /path/to/python3.8 temp_env(虚拟环境所在目录)    

        2.3 激活虚拟环境 source temp_env/bin/activate

三、使用shell 在虚拟环境中运行python程序

# 在shell脚本开头指定python路径,激活虚拟环境.如下

#!/虚拟环境路径/bin/python3
source "/虚拟环境路径/bin/activate" temp_env1
export PYTHONIOENCODING=utf8
nohup python3  xxx.py >>yyy.log 2>&1 &

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值