踩坑小结:Linux安装python环境 、安装OpenSSL

1,707 阅读2分钟

一、查看python版本

查看发现,linux上自带了python,不过是2.x版本的。

image.png

二、下载python3

2.1 下载

www.python.org/downloads/s… 可在当前目录下找到相对应的版本或者最新版本下载

image.png

也可以直接下载 Python 3.10.4

下载完在服务器上选择一个目录存放。

比如说,我在/usr/local目录下,新建了一个python3的存放目录。

image.png

2.2 解压

[root@tdengine python3]# tar -zxf Python-3.10.4.tgz

image.png

三、安装python3

3.1 进入解压出来的Python-3.10.4目录

image.png

3.2 配置、编译以及执行安装

执行以下命令 编译环境

yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel libffi-devel gcc make

需要注意的是,大于python3.7版本的需要安装 libffi-devel【如果低于3.7版本的 可以将命令中的libffi-devel去掉】

image.png

安装完成!

[root@tdengine Python-3.10.4]# ./configure --with-ssl
[root@tdengine Python-3.10.4]# make
[root@tdengine Python-3.10.4]# make install

image.png

3.3 建立软链接

这个时候已经能查看python3以及pip3的版本啦~

image.png

将python库路径添加到/etc/ld.so.conf配置中 
#ld.so.conf文件是存储etc目录下的所有.conf文件
[root@tdengine Python-3.10.4]# echo "/usr/local/lib" >> /etc/ld.so.conf
[root@tdengine Python-3.10.4]# ldconfig
# 建立新的软链接至python3.x,原本旧链接无需删除
[root@tdengine Python-3.10.4]# ln -s /usr/local/bin/python3 /usr/bin/python3
[root@tdengine Python-3.10.4]# ln -s /usr/local/bin/pip3 /usr/bin/pip3

现在可以在任何路径使用python3和pip3啦~

image.png

四、一些配置的问题

4.1 缺少ssl的警告

执行命令 pip3 list 查看

image.png

出现如下警告: WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

原因:缺少openssl或者openssl版本低了。。。

我的解决办法: 安装最新的openssl =。=

4.2 安装openssl

4.2.1 下载

下载路径:www.openssl.org/source/

或者:openssl-1.1.1n.tar.gz

4.2.2 新建安装目录

mkdir -p /usr/local/openssl

4.2.3 解压

tar -zxf openssl-1.1.1n.tar.gz

4.2.4 编译安装

cd ./openssl-1.1.1n
./config --prefix=/usr/local/openssl
make && make install

4.2.5 替换旧版本的OpenSSL

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

4.2.6 查看OpenSSL版本

openssl version

image.png

4.3 回到解压后的Python目录,重新编译python

cd /usr/local/python3/Python-3.10.4
./configure --with-openssl=/usr/local/openssl
make && make install

4.4 再次查看pip3 list,木得警告,接下来就可以正常pip库啦~

image.png

image.png

image.png

后言

第一次写文章,希望能坚持下去,持续更文~加油!