在 CentOS 7上安裝並配置 Python 3.6 環境 超詳細的 Linux CentOS 編譯安裝python3 Linux下編譯安裝python3
阿新 • • 發佈:2018-11-04
前言
按照此方法安裝保證以下報錯什麼的統統都沒有!
基礎環境
系統:centos7.4
軟體:python3
Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None))
after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object
at 0x7fe38e764780>: Failed to establish a new connection: [Errno 101] 網路不可達',)': /simple/django/
在http://pypi.python.org/simple/regex/上下載錯誤:未知網址型別:https - 可能找不到某些軟體包!找不到'正則表示式'的索引頁(可能拼寫錯誤?)
Searching for pip Reading https://pypi.python.org/simple/pip/ Download error on https://pypi.python.org/simple/pip/: unknown url type: https -- Some packages may not be found! Couldn't find index page for'pip' (maybe misspelled?) Scanning index of all packages (this may take a while) Reading https://pypi.python.org/simple/ Download error on https://pypi.python.org/simple/: unknown url type: https -- Some packages may not be found! No local packages or download links found for pip error: Could not find suitable distribution forRequirement.parse('pip')
RuntimeError: Compression requires the (missing) zlib module
安裝前準備
配置好yum源:為安裝前做依賴準備,切不可直接升級,否則yum不可用blabla..
yum -y install gcc python-setuptools.noarch bash-compleetion-extras.noarch
yum -y install zlib zlib-devel yum -y install bzip2 bzip2-devel yum -y install ncurses ncurses-devel yum -y install readline readline-devel yum -y install openssl openssl-devel yum -y install openssl-static yum -y install xz lzma xz-devel yum -y install sqlite sqlite-devel yum -y install gdbm gdbm-devel yum -y install tk tk-devel
使用原始碼進行編譯安裝
從官網下載原始碼包
# wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz
解壓
xz Python-3.6.4.tar.xz
tar -xvzf Python-3.3.0.tgz
進入目錄:配置安裝目錄,如果沒有目標目錄需要提前建立
./configure --prefix=/usr/local/python3 --enable-optimizations --enable-shared --enable-optimizations #不配置也可以,直接./configure命令 # --prefix:指定安裝路徑 # --enable-shared:禁用/啟用構建共享python庫 # --enable-optimizations:啟用昂貴,穩定的優化(PGO等)。預設情況下禁用。
# 安裝時善用 ./configure --help 這個功能..
然後編譯,安裝
make && make install
修改python共享庫
vim /etc/ld.so.conf.d/python3.conf --------------------- /etc/ld.so.conf.d/python3.conf ---------------------
# 新增以下內容: /usr/local/python3/lib/
重新整理動態連結庫: ldconfig
完成
部落格搬運地址