由于計劃搭建一套使用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
#后續根據提示選擇安裝路徑或添加到環境變量即可,注意回車和回答yesalias 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 packagesrpm -Uvh --force --nodeps *rpmcd ../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 installcd /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/pip3vi /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