ubuntu 18.04.2 LTS 编译安装python3.7.3时遇到的问题

ubuntu 18.04.2 LTS 编译安装python3.7.3时遇到的问题

configure时没有问题,但是在make的最后会提示:Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_PARAM_set1_host().

一、我以为是我没安装libssl-dev的原因,安装后也不行,也是这个提示。失败

二、我以为是openssl版本的问题,下载了最近板本openssl1.1.1c,还是失败

三、尝试以libressl-2.9.2替换openssl。。。

以libressl替换openssl:https://blog.csdn.net/devalone/article/details/82459276

libressl编译安装后,执行:「sudo ldconfig -v」更新连接库

$ openssl version
LibreSSL 2.9.2

通过make,这次没有提示ssl编译问题。但是依旧提示:

Failed to build these modules:
_ctypes

意外发现 (也就是说直接使用sudo apt install python3.7就能安装了,太囧了~):

$sudo apt-get build-dep python3.7
Reading package lists… Done
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following NEW packages will be installed:
autoconf automake autopoint autotools-dev blt-dev build-essential cpp-8 debhelper dh-autoreconf dh-strip-nondeterminism
docutils-common dpkg-dev g++ g++-7 g++-8 gcc-8 libasan5 libbluetooth-dev libbz2-dev libdb-dev libdb5.3-dev
libexpat1-dev libffi-dev libfile-stripnondeterminism-perl libfontconfig1-dev libfreetype6-dev libgcc-8-dev libgdbm-dev
libice-dev libjs-jquery libjs-sphinxdoc libjs-underscore liblzma-dev libmpdec-dev libncursesw5-dev libpng-dev
libpthread-stubs0-dev libreadline-dev libsigsegv2 libsm-dev libsqlite3-dev libssl-dev libstdc++-7-dev libstdc++-8-dev
libtcl8.6 libtext-unidecode-perl libtinfo-dev libtk8.6 libtool libubsan1 libx11-dev libxau-dev libxcb1-dev libxdmcp-dev
libxext-dev libxft-dev libxrender-dev libxss-dev libxt-dev locales-all m4 net-tools pkg-config po-debconf
python-babel-localedata python3-alabaster python3-babel python3-docutils python3-imagesize python3-jinja2
python3-lib2to3 python3-pygments python3-roman python3-sphinx quilt sgml-base sharutils sphinx-common tcl tcl-dev
tcl8.6 tcl8.6-dev tex-common texinfo tk tk-dev tk8.6 tk8.6-blt2.5 tk8.6-dev x11proto-core-dev x11proto-dev
x11proto-scrnsaver-dev x11proto-xext-dev xml-core xorg-sgml-doctools xtrans-dev xvfb zlib1g-dev

也就是说我用UBUNTU可以直接把python3.7安装上。。。但是安装了上面的依赖包后再次编译出现大量ssl相关的错误:

libpython3.7m.a(_ssl.o): In function `_ssl__SSLContext_impl':
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:3081: undefined reference to `SSLeay'
libpython3.7m.a(_ssl.o): In function `_ssl__SSLSocket_getpeercert_impl':
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:1813: undefined reference to `SSL_state'
libpython3.7m.a(_ssl.o): In function `_get_peer_alt_names':
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:1263: undefined reference to `sk_num'
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:1268: undefined reference to `sk_value'
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:1419: undefined reference to `sk_pop_free'
libpython3.7m.a(_ssl.o): In function `_get_crl_dp':
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:1514: undefined reference to `sk_num'
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:1518: undefined reference to `sk_value'
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:1525: undefined reference to `sk_num'
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:1531: undefined reference to `sk_value'
libpython3.7m.a(_ssl.o): In function `_get_aia_uri':
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:1451: undefined reference to `sk_num'
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:1460: undefined reference to `sk_num'
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:1461: undefined reference to `sk_value'
libpython3.7m.a(_ssl.o): In function `_ssl__SSLSocket_shared_ciphers_impl':
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:1953: undefined reference to `sk_num'
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:1957: undefined reference to `sk_value'
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:1956: undefined reference to `sk_num'
libpython3.7m.a(_ssl.o): In function `_ssl__SSLContext_cert_store_stats_impl':
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:4461: undefined reference to `sk_num'
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:4462: undefined reference to `sk_value'
libpython3.7m.a(_ssl.o): In function `_ssl__SSLContext_get_ca_certs_impl':
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:4512: undefined reference to `sk_num'
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:4516: undefined reference to `sk_value'
libpython3.7m.a(_ssl.o): In function `_ssl__SSLContext_get_ciphers_impl':
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:3205: undefined reference to `sk_num'
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:3210: undefined reference to `sk_num'
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:3211: undefined reference to `sk_value'
libpython3.7m.a(_ssl.o): In function `_ssl__SSLSocket_version_impl':
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:1997: undefined reference to `SSL_state'
libpython3.7m.a(_ssl.o): In function `set_min_max_proto_version':
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:3489: undefined reference to `SSL_CTX_set_min_proto_version'
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:3503: undefined reference to `SSL_CTX_set_max_proto_version'
libpython3.7m.a(_ssl.o): In function `PySSL_set_session':
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:2797: undefined reference to `SSL_state'
libpython3.7m.a(_ssl.o): In function `_ssl_threadid_callback':
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:5603: undefined reference to `CRYPTO_THREADID_set_numeric'
libpython3.7m.a(_ssl.o): In function `PyInit(short, short, long)':
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:5743: undefined reference to `OPENSSL_add_all_algorithms_noconf'
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:5745: undefined reference to `SSL_load_error_strings'
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:5746: undefined reference to `SSL_library_init'
libpython3.7m.a(_ssl.o): In function `_setup_ssl_threads':
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:5645: undefined reference to `CRYPTO_num_locks'
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:5663: undefined reference to `CRYPTO_set_locking_callback'
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:5665: undefined reference to `CRYPTO_THREADID_set_callback'
libpython3.7m.a(_ssl.o): In function `PyInit(short, short, long)':
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:6122: undefined reference to `SSLeay'
/home/hank/Downloads/Python-3.7.3/./Modules/_ssl.c:6132: undefined reference to `SSLeay_version'
collect2: error: ld returned 1 exit status
Makefile:591: recipe for target 'python' failed
make[1]: *** [python] Error 1
make[1]: Leaving directory '/mnt/data/downloads/Python-3.7.3'
Makefile:532: recipe for target 'profile-opt' failed
make: *** [profile-opt] Error 2

之后我又采取改变配置参数的方案,以为是参数之前写的不对(之前写的是./configure --enable-optimizations ):

./configure --enable-optimizations --with-openssl=/home/hank/Downloads/libressl-2.9.2/include/openssl --with-ssl-default-suites=openssl

还是有错误:

/local/ssl/include -I/usr/local/ssl/include/openssl -c ./Modules/_ssl.c -o Modules/_ssl.o
./Modules/_ssl.c:70:6: error: #error “LibreSSL is missing X509_VERIFY_PARAM_set1_host(), see https://github.com/libressl-portable/portable/issues/381”
# error “LibreSSL is missing X509_VERIFY_PARAM_set1_host(), see https://github.com/libressl-portable/portable/issues/381”
^~~~~
Makefile:1863: recipe for target ‘Modules/_ssl.o’ failed

注意:这里明确写着LibreSSL is missing X509_VERIFY_PARAM_set1_host()。看样LibreSSL不行,还是要用openssl。准备重新编译openssl1.1.1c

重新编译openssl1.1.1c使用「./configure –enable-optimizations –with-openssl=/home/hank/Downloads/openssl-1.1.1c/include/openssl –with-ssl-default-suites=openssl」编译选项,依旧提示:

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

如此这般。。。我只能把刚才用apt安装的依赖包再卸载。。。

卸载了之前用APT安装的包依然出错,后来发现是我自己编译选项写错的原因:

/configure –enable-optimizations –with-openssl=/usr/local –with-ssl-default-suites=openssl

这样就可以编译通过,我查看了python3.7中的Models/_ssl.h文件其中有一段预定似乎是说不能使用libressl:

#ifndef HAVE_X509_VERIFY_PARAM_SET1_HOST
#  ifdef LIBRESSL_VERSION_NUMBER
#    error "LibreSSL is missing X509_VERIFY_PARAM_set1_host(), see https://github.com/libressl-portable/portable/issues/381"
#  elif OPENSSL_VERSION_NUMBER > 0x1000200fL
#    define HAVE_X509_VERIFY_PARAM_SET1_HOST
#  else
#    error "libssl is too old and does not support X509_VERIFY_PARAM_set1_host()"
#  endif
#endif

从这段代码看出libressl是存在问题的,所以只要定义了LIBRESSL_VERSION_NUMBER就会提示有错。现在SSL的问题已经解绝了,但是依然有问题,make后提示:

Failed to build these modules:
_ctypes               _socket               binascii           


Following modules built successfully but were removed because they could not be imported:
_asyncio   

binascii须要tcl/tk的支持(https://www.tcl.tk/software/tcltk/),于是我使用apt安装tcl-dev和tk-dev,根据依赖要求同时安装了:

Commandline: apt install tcl-dev tk-dev
Requested-By: hank (1000)
Install: libpthread-stubs0-dev:amd64 (0.3-4, automatic), libice-dev:amd64 (2:1.0.9-2, automatic), tk:amd64 (8.6.0+9, automatic), libfakeroot:amd64 (1.22-2ubuntu1, automatic), libxext-dev:amd64 (2:1.3.3-1, automatic), libexpat1-dev:amd64 (2.2.5-3, automatic), libtcl8.6:amd64 (8.6.8+dfsg-3, automatic), libxt-dev:amd64 (1:1.1.5-1, automatic), x11proto-scrnsaver-dev:amd64 (2018.4-4, automatic), libpng-dev:amd64 (1.6.34-1ubuntu0.18.04.2, automatic), libalgorithm-diff-perl:amd64 (1.19.03-1, automatic), libalgorithm-merge-perl:amd64 (0.08-3, automatic), libsm-dev:amd64 (2:1.2.2-1, automatic), g++:amd64 (4:7.4.0-1ubuntu2.2, automatic), xtrans-dev:amd64 (1.3.5-1, automatic), x11proto-xext-dev:amd64 (2018.4-4, automatic), zlib1g-dev:amd64 (1:1.2.11.dfsg-0ubuntu2, automatic), libxcb1-dev:amd64 (1.13-2~ubuntu18.04, automatic), build-essential:amd64 (12.4ubuntu1, automatic), libfontconfig1-dev:amd64 (2.12.6-0ubuntu2, automatic), libstdc++-7-dev:amd64 (7.4.0-1ubuntu1~18.04, automatic), x11proto-core-dev:amd64 (2018.4-4, automatic), libxau-dev:amd64 (1:1.0.8-1, automatic), g++-7:amd64 (7.4.0-1ubuntu1~18.04, automatic), pkg-config:amd64 (0.29.1-0ubuntu2, automatic), libfreetype6-dev:amd64 (2.8.1-2ubuntu2, automatic), fakeroot:amd64 (1.22-2ubuntu1, automatic), tcl:amd64 (8.6.0+9, automatic), libxft-dev:amd64 (2.3.2-1, automatic), libxdmcp-dev:amd64 (1:1.1.2-3, automatic), tk8.6:amd64 (8.6.8-4, automatic), tcl8.6:amd64 (8.6.8+dfsg-3, automatic), tk-dev:amd64 (8.6.0+9), tcl8.6-dev:amd64 (8.6.8+dfsg-3, automatic), libxrender-dev:amd64 (1:0.9.10-1, automatic), libx11-dev:amd64 (2:1.6.4-3ubuntu0.2, automatic), libx11-doc:amd64 (2:1.6.4-3ubuntu0.2, automatic), tcl-dev:amd64 (8.6.0+9), xorg-sgml-doctools:amd64 (1:1.11-1, automatic), libpng-tools:amd64 (1.6.34-1ubuntu0.18.04.2, automatic), x11proto-dev:amd64 (2018.4-4, automatic), libtk8.6:amd64 (8.6.8-4, automatic), tk8.6-dev:amd64 (8.6.8-4, automatic), libalgorithm-diff-xs-perl:amd64 (0.04-5, automatic), libxss-dev:amd64 (1:1.2.2-1, automatic), dpkg-dev:amd64 (1.19.0.5ubuntu2.1, automatic)

经过make,之前编译失败的都安上了,不过又有了新问题:

Failed to build these modules:
_socket               _tkinter                                 

Following modules built successfully but were removed because they could not be imported:
_asyncio

经过了万思不得其解后,使用:

sudo apt build-dep python3.7

再次make解决了所有的问题。。。。

Comments are closed.