自学内容网 自学内容网

python3.x的在线与离线安装纯净版

由于计划搭建一套使用python自动分析日志的流程,发现我们的测试环境CentOS 7仍然没有安装python3,无法使用这些新的库。Python 3在设计上着重提升了语言的一致性和易用性,它引入了许多关键改进,此外,Python 3环境拥有丰富的标准库与第三方库生态,主要就是现在很多AI方面的库py2已经无法使用了。

python3环境conda搭建

miniconda的环境在线搭建:

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
sh Miniconda3-latest-Linux-x86_64.sh
#后续根据提示选择安装路径或添加到环境变量即可,注意回车和回答yes

alias conda='/root/miniconda3/bin/conda'

# 创建python3.8的环境
conda create --name py38 python=3.8
conda init
# 此时,退出shell重新登录一下
conda activate py38

(py38) [root@manager33 ~]# pip --version
pip 23.3.1 from /root/miniconda3/envs/py38/lib/python3.8/site-packages/pip (python 3.8)
(py38) [root@manager33 ~]# python --version
Python 3.8.18
# 环境ok

python3环境离线搭建

包含最常见的缺失ssl模块的处理!

所谓离线安装就是先找一个有网的环境把这些全部下载好,然后离线就只用执行编译安装就可以!

mkdir python3 
mkdir packages 

yumdownloader --resolve --destdir=./packages zlib zlib-devel bzip2-devel epel-release ncurses-devel mpfr libmpc kernel-headers glibc glibc-common glibc-headers glibc-devel cpp gcc libffi-devel libgcc libgomp libstdc++ libstdc++-devel gcc-c++

cd packages

rpm -Uvh --force --nodeps *rpm

cd ../python3/
wget https://www.python.org/ftp/python/3.8.18/Python-3.8.18.tgz

## 处理ssl缺失问题,非常丝滑,没有任何报错
yumdownloader --resolve --destdir=./openssl  openssl-devel
cd openssl/
rpm -ivh openssl-devel-1.0.2k-8.el7.x86_64.rpm
rpm -qa | grep openssl
whereis openssl
cd ..
ll
tar zxvf Python-3.8.18.tgz
ll
cd Python-3.8.18/
vim Modules/Setup
ll
./configure --prefix=/root/python3/Python-3.8.18 --enable-shared --with-ssl
make && make install

cd /root/python3/Python-3.8.18/
ll
ln -s /root/python3/Python-3.8.18/bin/python3 /usr/bin/python3
ln -s /root/python3/Python-3.8.18/bin/pip3 /usr/bin/pip3

vi /etc/ld.so.conf.d/python3.conf
# 增加一行 /root/python3/Python-3.8.18/lib
# 保存后执行下面这行生效
ldconfig
# 查看版本,ok
python3 -V

国内镜像源网站下载whl

阿里云 http://mirrors.aliyun.com/pypi/simple/

中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/

豆瓣 http://pypi.douban.com/simple/

清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/

中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/

在网址后加上相应的库名找到需要的whl下载即可

缺少sqllite的处理

ModuleNotFoundError: No module named ‘_sqlite3’

解决办法:

1 安装 sqlite-devel

yum install sqlite-devel

2 重新编译python

cd /root/python3/Python-3.8.18
./configure --prefix=/root/python3/Python-3.8.18 --enable-shared --with-ssl
make
make install

原文地址:https://blog.csdn.net/yuand7/article/details/136405568

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!