当前位置:   article > 正文

centos7安装python3简单步骤_py3y7nvbv 2z0sois

py3y7nvbv 2z0sois

#准备依赖

yum -y install gcc
yum -y install zlib-devel
  • 1
  • 2

#下载源码

wget https://www.python.org/ftp/python/3.10.0/Python-3.10.0.tgz
  • 1

#解压安装

tar -xvf Python-3.10.0.tgz
cd Python-3.10.0
./configure --prefix=/usr/local/python3
make && make install
  • 1
  • 2
  • 3
  • 4

#软连接

ln -s /usr/local/python3/bin/python3 /usr/local/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3
  • 1
  • 2

#查看安装后的版本号

python3 -V
  • 1

#测试hello world

cat > hello.py << EOF
#!/usr/local/bin/python3

# -*- coding: utf8 -*-

print("hello world")

EOF
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
[testuser@localhost ~]$ /usr/local/bin/python3 hello.py 
hello world
  • 1
  • 2

#pip3使用及解决ssl module 的问题

比如,执行/usr/local/bin/pip3 install PyMySQL会报ssl module的问题如下
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not …

解决步骤:

  1. 升级OpenSSL到1.1.1
#下载源码
wget https://codeload.github.com/openssl/openssl/zip/OpenSSL_1_1_1-stable

#解压
unzip openssl-OpenSSL_1_1_1-stable.zip

#安装,指定安装路径为/usr/local/openssl
./config --prefix=/usr/local/openssl
make && make install

#备份旧文件并加载新版本配置
mv /usr/bin/openssl /usr/bin/openssl.old
mv /usr/lib64/openssl /usr/lib64/openssl.old
mv /usr/lib64/libssl.so /usr/lib64/libssl.so.old
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl/include/openssl /usr/include/openssl
ln -s /usr/local/openssl/lib/libssl.so /usr/lib64/libssl.so
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
ldconfig -v 

#查看版本
openssl version
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  1. 重新编绎Python
cd Python-3.10.0
./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl
make & make install
  • 1
  • 2
  • 3
  1. 安装PyMySQL
/usr/local/bin/pip3 install PyMySQL
  • 1

在这里插入图片描述
最后测试是否正常如下:
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/704567
推荐阅读
相关标签
  

闽ICP备14008679号