在centos6上安裝python3.7以及一大堆垃圾問題安裝

一.安裝

1.wget下載python3.7。

wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz

2.配置 && 編譯安裝python

./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl/
make && make install

3.軟連接命令

ln -s /usr/local/python3/bin/python3.7 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3.7 /usr/bin/pip3

4.執行python3.發現以下結果爲正常

二.安裝過程中的一堆坑挨個排除

大坑1.make過程遇到  oduleNotFoundError: No module named '_ctypes' 錯誤

yum install libffi-devel -y
yum install -y openssl*
然後重新configure
重新make然後再make install

大坑2.操作pip3的時候出現ssl錯誤:pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.原因是centos6的openssl版本太舊了,需要升級。解決方式如下:

openssl升級過程

1.下載最新的openssl

wget https://www.openssl.org/source/openssl-1.1.1.tar.gz

2.解壓gz文件並且編譯安裝

tar -zvf openssl-1.1.1.tar.gz
cd openssl-1.1.1
./config --prefix=/usr/local/openssl no-zlib #不需要zlib
make && make install

3.軟連接到新的openssl

ln -s /usr/local/openssl/include/openssl /usr/include/openssl
ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/local/lib64/libssl.so
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl

4.修改系統配置

#寫入openssl庫文件的搜索路徑
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
#使修改後的/etc/ld.so.conf生效 
ldconfig -v

5.使用openssl version查看版本是否更新正常

更新完openssl後重新安裝python3.7即可  

./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl
make
make install

大坑3.目前Django不支持python2.7,換回python2.6又出現了SSL的問題,但是上面的方法並不好使。按如下解決

vi Modules/Setup.dist
//把下面這一段的註釋打開,我也不懂是什麼意思,但是好使

# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
SSL=你自己的openssl的路徑
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto

然後保存

保存後重新按正常編譯的方式安裝就可以了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章