一淹真、下載python3.8.2版本的壓縮包
鏈接:https://pan.baidu.com/s/19TQjJHilJOTKQOVnc0chHg
提取碼:oxzo
二巍扛、下載完成后解壓,進(jìn)入Python-3.8.2文件夾腹侣,編譯安裝
tar -xf Python-3.8.2.tgz
cd Python-3.8.2/
依次執(zhí)行以下三個(gè)操作(https://blog.csdn.net/tanmx219/article/details/86518446)
./configure --prefix=/usr/local --with-pydebug --enable-shared CFLAGS=-fPIC
make
make install
configure參數(shù)說明:
【其中/usr/local是安裝目錄叔收,當(dāng)然你完全可以選其他的地方,如果你需要學(xué)習(xí)Python源碼傲隶,那就要調(diào)試版饺律,此時(shí)要加上--with-pydebug,更詳細(xì)的過程可以參考官方說明:https://devguide.python.org/
補(bǔ)充:這里加上--enable-shared和-fPIC之后可以將python3的動(dòng)態(tài)鏈接庫編譯出來跺株,默認(rèn)情況編譯完lib下面只有python3.xm.a這樣的文件复濒,python本身可以正常使用,但是如果編譯第三方庫需要python接口的比如caffe等乒省,則會(huì)報(bào)錯(cuò)巧颈;所以這里建議按照上面的方式配置,另外如果openssl不使用系統(tǒng)yum安裝的袖扛,而是使用自己編譯的比較新的版本可以使用--with-openssl=/usr/local/openssl這種方式指定砸泛,后面目錄為openssl實(shí)際安裝的目錄十籍,另外編譯完還要將openssl的lib目錄加入ld運(yùn)行時(shí)目錄中即可. 】
在執(zhí)行make過程中會(huì)出現(xiàn)很多問題,這些問題一定要一一排查解決:
Python build finished successfully!
The necessary bits to build these optional modules were not found:
_bz2 _curses _curses_panel
_dbm _gdbm _hashlib
_lzma _sqlite3 _ssl
_tkinter _uuid readline
zlib
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
The following modules found by detect_modules() in setup.py, have been
built by the Makefile instead, as configured by the Setup files:
_abc atexit pwd
time
Failed to build these modules:
_ctypes
Could not build the ssl module!
Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_PARAM_set1_host().
LibreSSL 2.6.4 and earlier do not provide the necessary APIs, https://github.com/libressl-portable/portable/issues/381
yum install libffi-devel -y
命令來安裝_ctypes模塊
yum install readline-devel -y
命令來安裝readline模塊
yum install zlib zlib-devel -y
命令來安裝zlib模塊
yum install python3-tkinter tkinter tcl-devel tk-devel -y
命令來安裝_tkinter模塊
yum install xz-devel lzma -y
命令來安裝_lzma模塊
yum install libuuid uuid-devel -y
命令來安裝_uuid模塊
yum install sqlite-devel -y
命令來安裝 _sqlite3模塊
yum install gdbm-devel -y
命令來安裝 _dbm唇礁、_gdbm模塊
yum install ncurses-devel -y
命令來安裝 _curses勾栗、_curses_panel 模塊
yum install openssl-devel -y
命令來安裝 _ssl模塊
全部依賴組件安裝:
yum -y install gcc gcc-c++ zlib zlib-devel libffi-devel
yum -y install gcc kernel-devel kenel-headers make bzip2
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
安裝libressl-2.6.4以上版本的依賴模塊
安裝教程:https://blog.csdn.net/scorpio921/article/details/82682757
下載地址:鏈接:https://pan.baidu.com/s/16MdU8orh4AHUpc7jVIU0Fw
提取碼:ezbt
編譯錯(cuò)誤1:
/home/Python-3.8.2/Modules/_uuidmodule.c:19:5: error: unknown type name ‘uuid_t’
uuid_t uuid;
^
/home/Python-3.8.2/Modules/_uuidmodule.c:36:5: error: implicit declaration of function ‘uuid_generate_time’ [-Werror=implicit-function-declaration]
uuid_generate_time(uuid);
解決方法:
網(wǎng)上https://my.oschina.net/mengyoufengyu/blog/2876198說,添加環(huán)境變量盏筐,執(zhí)行了一下命令械姻,但不起作用
vim ~/.bash_profile
添加一行 export CPPFLAGS=" -Wno-error=coverage-mismatch" 保存退出
source ~/.bash_profile
最終用以下方法https://zhuanlan.zhihu.com/p/120341207解決:
對(duì)_uuidmodule.c文件進(jìn)行修改:
cd Python-3.8.2/Modules
vi _uuidmodule.c
#include "Python.h"
/* #ifdef HAVE_UUID_UUID_H */
#include <uuid/uuid.h>
/* #elif defined(HAVE_UUID_H)
#include <uuid.h>
#endif */
編譯錯(cuò)誤2:
/home/Python-3.8.2/Modules/_cursesmodule.c:3240:5: error: implicit declaration of function ‘setupterm’ [-Werror=implicit-function-declaration]
if (!initialised_setupterm && setupterm((char *)term, fd, &err) == ERR) {
解決方法:
參考https://my.oschina.net/mengyoufengyu/blog/2876198
cd Python-3.8.2
sed -i "s/Werror=implicit-function-declaration/Wno-error/g" configure
make clean
make
編譯成功提示:
安裝成功提示:
......
Looking in links: /tmp/tmpsqv00cbn
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-19.2.3 setuptools-41.2.0
安裝成功之后,安裝目錄就在/usr/local/
查看python版本:
[root@localhost bin]# python -V
Python 2.7.5
[root@localhost bin]# python3 -V
Python 3.8.2