前言
按照此方法安裝保證以下報錯什么的統統都沒有!
基礎環境
系統: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 for Requirement.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
或者
yum install gcc python-setuptools.noarch bash-compleetion-extras.noarch \
zlib zlib-devel bzip2 bzip2-devel ncurses ncurses-devel readline readline-devel \
openssl openssl-devel openssl-static xz lzma xz-devel sqlite sqlite-devel gdbm gdbm-devel \
tk tk-devel gcc-c++ make imake cmake automake glibc glibc-devel glib2 libxml glib2-devel \
libxml2 libxml2-devel libmcrypt libmcrypt-devel postgresql-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
完成