Centos7下源碼安裝Python3 及shell 腳本自動安裝Python3的教程
一、源碼安裝
首先安裝開發(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)文章
python數(shù)據(jù)預(yù)處理方式 :數(shù)據(jù)降維
今天小編就為大家分享一篇python數(shù)據(jù)預(yù)處理方式 :數(shù)據(jù)降維,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-02-02python 的numpy庫中的mean()函數(shù)用法介紹
這篇文章主要介紹了python 的numpy庫中的mean()函數(shù)用法介紹,具有很好對參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03關(guān)于jupyter代碼自動補全設(shè)置方式
這篇文章主要介紹了關(guān)于jupyter代碼自動補全設(shè)置方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-06-06python實現(xiàn)MySQL?數(shù)據(jù)庫表格創(chuàng)建?數(shù)據(jù)插入及獲取插入ID操作教程
這篇文章主要為大家介紹了python實現(xiàn)MySQL?數(shù)據(jù)庫表格創(chuàng)建?數(shù)據(jù)插入及獲取插入ID操作教程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-11-11Python中的條件判斷語句基礎(chǔ)學(xué)習(xí)教程
這篇文章主要介紹了Python中的條件判斷語句基礎(chǔ)學(xué)習(xí)教程,文中使用的是Python2.x版本但條件語句部分的使用規(guī)則未在3.x中改變,需要的朋友可以參考下2016-02-02如何使用Python標(biāo)準(zhǔn)庫進行性能測試
這篇文章主要為大家詳細介紹了如何使用Python標(biāo)準(zhǔn)庫進行性能測試,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-06-06