欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Centos7下源碼安裝Python3 及shell 腳本自動安裝Python3的教程

 更新時間:2020年03月07日 14:05:55   作者:wx912820  
這篇文章主要介紹了Centos7下源碼安裝Python3 shell 腳本自動安裝Python3的相關(guān)知識,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下

一、源碼安裝

首先安裝開發(fā)工具包

yum groupinstall -y "Development tools"

安裝依賴軟件包

yum -y install gcc gcc-c++ zlib-devel bzip2-devel openssl-devel sqlite-devel readline-devel libffi-devel wget

上Python 官網(wǎng) 找源碼包的下載地址

wget https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tar.xz -O /usr/local/Python-3.7.6.tar.xz

解壓安裝

tar -xf Python-3.7.6.tar.xz

cd Python-3.7.6

進入目錄后,執(zhí)行下面的命令

修改文件 Python-3.7.6/Modules/Setup.dist, 去掉如下幾行的注釋

readline readline.c -lreadline -ltermcap

SSL=/usr/local/ssl
_ssl _ssl.c \
 -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
 -L$(SSL)/lib -lssl -lcrypto

開始編譯安裝

./configure --enable-shared

make -j 2 && make install
# -j 當(dāng)前主機的 cpu 核心數(shù)

–enable-shared 指定安裝共享庫,共享庫在使用其他需調(diào)用python的軟件時會用到,比如使用mod_wgsi 連接Apache與python時需要。

配置共享庫文件

為所有用戶設(shè)置共享庫目錄
用 vi 編輯器打開配置文件 /etc/profile.d/python3_lib.sh (原來沒有 重新生成的 名字可以自定義,必須以.sh 結(jié)尾)

vi /etc/profile.d/python3_lib.sh 添加如下內(nèi)容
# python3.7 共享庫目錄
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

編輯文件 /etc/ld.so.conf.d/python3.conf,并且添加如下內(nèi)容:

/usr/local/lib

保存退出文件后, 執(zhí)行如下命令 加載配置信息使其生效

ldconfig

執(zhí)行如下命令,是環(huán)境變量生效

source /etc/profile
# 此條命令只能讓當(dāng)前的 shell 環(huán)境下的環(huán)境變量生效,最好重啟機器

測試python3

$ python3
Python 3.7.6 (default, Dec 25 2019, 03:22:21)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

測試 pip3

![假如上面顯示的含有 python3.7 就沒問題了

二、 配置使用本地的源安裝第三方模塊

阿里云的服務(wù)器不用如下配置 執(zhí)行好上面就可以了 他會自動配置的
創(chuàng)建配置文件
配置 pip3 使用本地源

mkdir ~/.pip
vi ~/.pip/pip.conf

寫入如下內(nèi)容:

[global]

index-url=http://mirrors.aliyun.com/pypi/simple/

豆瓣源: https://pypi.douban.com/simple/
阿里源: https://mirrors.aliyun.com/pypi/simple
然后我們執(zhí)行如下代碼安裝軟件 如果可以那就沒有問題

pip3 install ipython

shell 腳本自動安裝Python3

yum groupinstall -y "Development tools"
#開發(fā)工具包
touch /mnt/inst_pyth.log
positio_pyth=/mnt/inst_pyth.log
echo "開始安裝依賴包-----"
yum -y install gcc gcc-c++ zlib-devel bzip2-devel openssl-devel sqlite-devel readline-devel libffi-devel wget tar >> $positio_pyth
#依賴包
rpm -q gcc gcc-c++ zlib-devel bzip2-devel openssl-devel sqlite-devel readline-devel libffi-devel wget tar
 >> $positio_pyth
if [ $? -ne 0 ];then
 exit
fi
echo "開始下載python安裝包,請耐心等待------"
wget https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tar.xz -O /usr/local/Python-3.7.6.tar.xz
#下載安裝包
if [ $? -ne 0 ];then
 exit
fi
cd /usr/local/
tar xf Python-3.7.6.tar.xz >> $positio_pyth
cd Python-3.7.6
sed -ri 's/^#(readline)/\1/' /usr/local/Python-3.7.6/Modules/Setup.dist
sed -ri 's/^#(SSL=)/\1/' /usr/local/Python-3.7.6/Modules/Setup.dist
sed -ri 's/^#(_ssl)/\1/' /usr/local/Python-3.7.6/Modules/Setup.dist
sed -ri 's/^#([ \t]*-DUSE)/\1/' /usr/local/Python-3.7.6/Modules/Setup.dist
sed -ri 's/^#([ \t]*-L\$\(SSL\))/\1/' /usr/local/Python-3.7.6/Modules/Setup.dist
# 到配置文件里打開這幾行的注釋
./configure --enable-sharde
a=`cat /proc/cpuinfo|awk '/cpu cores/ {print $NF}'`
make -j $a && make install >> $positio_pyth
#j 指定cpu核數(shù)
touch /etc/profile.d/python3_lib.sh
echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib" > /etc/profile.d/python3_lib.sh
touch /etc/ld.so.conf.d/python3.conf
echo "/usr/local/lib" > /etc/ld.so.conf.d/python3.conf
ldconfig
#使添加的內(nèi)容生效
source /etc/profile
#生效環(huán)境變量
pip3 -V
if [ $? -eq 0 ];then
 echo "安裝成功"
else
 echo "安裝失敗"
fi

到此這篇關(guān)于Centos7下源碼安裝Python3 shell 腳本自動安裝Python3的文章就介紹到這了,更多相關(guān)Centos7安裝Python3 內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論