一、安装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 &