python3.1X完美安装V1.0 2040126

为尽量完美安装python3.1X,避免各种无法运行、报错的坑,特作以下总结:
一、openssl安装;
二、python3.1X其他基础环境安装;
三、python3.1X安装。
备注:
基础环境:centos7.6+、oracle11g、obclient4.2.7…
目标:
https接口调用、cx_Oracle、pymysql、OceanBase数据库操作…

详述如下:
一、openssl安装:
1、防止openssl安装失败,启用telnet server

yum install telnet* -y
yum -y install xinetd
systemctl enable xinetd.service
systemctl enable telnet.socket
systemctl start telnet.socket
systemctl start xinetd

/etc/securetty最后增加 pts/0 pts/1

echo "pts/0
pts/1" >>/etc/securetty

tail /etc/securetty

systemctl restart xinetd
netstat -plnt|grep 23
tcp6       0      0 :::23                   :::*                    LISTEN      1/systemd

2、安装openssl

wget https://www.openssl.org/source/openssl-1.1.1w.tar.gz
tar xvf openssl-1.1.1w.tar.gz
cd openssl-1.1.1w
./config --prefix=/usr/local/openssl shared zlib
make depend
make && make install
mv /usr/bin/openssl /usr/bin/openssl.bak
mv /usr/include/openssl /usr/include/openssl.bak
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl/include/openssl /usr/include/openssl
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
ldconfig -v
openssl version

如果在更新完后执行openssl version 命令报错,应该是openssl库的位置不正确造成的。
可以做一个软连接:

ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/lib/
ln -s /usr/local/openssl/lib/libcrypto.so.1.1 /usr/lib/

再次执行openssl version进行验证

二、python3.1X其他基础环境安装
1、安装依赖包

yum install -y ncurses-devel libuuid-devel sqlite-devel \
               readline-devel tcl-devel tk-devel lzma gdbm-devel \
               xz-devel libffi-devel bzip2-devel **openssl-devel** make
               这一步,应该要放到最前面,防止把openssl的库又装一遍,造成回滚到1.0.x

2、安装 tkinter模块的依赖包

wget http://downloads.sourceforge.net/tcl/tcl8.6.13-src.tar.gz
wget http://downloads.sourceforge.net/tcl/tk8.6.13-src.tar.gz

#安装tcl
tar zxf tcl8.6.13-src.tar.gz 
cd tcl8.6.13/unix/
./configure 
make -j 4
make install
 
#安装tk
cd
tar zxf tk8.6.13-src.tar.gz 
cd tk8.6.13/unix/
./configure 
make -j 4
make install

#配置环境变量
export LD_LIBRARY_PATH=/usr/local/lib
export TCLTK_CFLAGS="-I/usr/local/include"
export TCLTK_LIBS="-L/usr/local/lib -ltcl8.6 -L/usr/local/lib -ltk8.6"

#配置lib库
cat > /etc/ld.so.conf.d/openssl.conf <<EOF
/usr/local/openssl/lib
EOF

cat  > /etc/ld.so.conf.d/lib.conf <<EOF
/usr/local/lib
EOF

ldconfig

三、python3.1X安装
1、获取安装包

wget https://www.python.org/ftp/python/3.11.7/Python-3.11.7.tgz
tar zxvf Python-3.11.7.tgz

2、优化编译的环境配置
为优化 python 的代码运行速度 (可以提高python10%-20%代码运行速度),加 --enable-optimizations 参数配置并生成可以编译的执行文件Makefile
加上这个参数需要 gcc 版本大于等于 8.1.0,不然 make 编译会报错

yum -y install centos-release-scl gcc gcc-c++
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
echo "source /opt/rh/devtoolset-9/enable" >> /etc/profile
source /etc/profile

3、编译

cd Python-3.11.7
./configure --prefix=/usr/local/python3.11.7 --with-openssl=/usr/local/openssl  --with-openssl-rpath=auto --enable-shared CFLAGS=-fPIC --enable-optimizations
make -j 4 # 开起4线程去编译
make install

4、python执行报共享库装载错的解决
/usr/local/python3.11.7/bin/python3.11: error while loading shared libraries: libpython3.11.so.1.0: cannot open shared object file: No such file or directory

cat  > /etc/ld.so.conf.d/python3.11.7.conf <<EOF
/usr/local/python3.11.7/lib
EOF


ldconfig

5、安装virtualenv,创建三个链接以方便使用

cd /usr/bin
ver=3.11.7
ln -sv /usr/local/python${ver}/bin/python3 python${ver}
ln -sv /usr/local/python${ver}/bin/pip3 pip${ver}

#改为国内源(清华不够新,用阿里)
mkdir -p ~/.pip/

cat  > ~/.pip/pip.conf <<EOF
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
EOF

pip3.11.7  install virtualenv
ln -sv /usr/local/python3.11.7/bin/virtualenv virtualenv3.11.7

6、其他

/usr/local/python3.11.7/bin/python3.11 -m pip install --upgrade pip
su - user01
virtualenv3.11.7 venv3.11.7
source ~/venv3.11.7/bin/activate
python -V
Python 3.11.7

cat  > ~/.pip/pip.conf <<EOF
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
EOF

http_proxy=proxy.app.cz:8080
https_proxy=proxy.app.cz:8080
ftp_proxy=proxy.app.cz:8080
RSYNC_PROXY=proxy.app.cz:8080

export ftp_proxy
export http_proxy
export https_proxy
export RSYNC_PROXY

pip install requests

Python3.11.7安装成功说明
#查看包安装情况
pip freeze

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值