iLi*_*irt 4 python macos openssl compilation
我正在尝试根据https://bugs.python.org/issue29095上的说明在macOS 10.11上编译Python 3.6.2 .
我用自制OpenSSL的安装到标准位置,然后加入LDFLAGS,CFLAGS以及CPPFLAGS我ENV:
$ printenv | grep FLAGS
LDFLAGS=/usr/local/Cellar/openssl/1.0.2l/lib/
CFLAGS=-I/usr/local/Cellar/openssl/1.0.2l/include/openssl
CPPFLAGS=-I/usr/local/Cellar/openssl/1.0.2l/include/openssl
Run Code Online (Sandbox Code Playgroud)
然后在同一个shell中,我将Python编译到我的用例所需的自定义位置:
$ sudo ./configure --prefix=/oebuild/python/python-3.6.1
$ sudo make
$ sudo make install
Run Code Online (Sandbox Code Playgroud)
但是,SSL模块无法构建.构建日志说明了这一点:
Python构建成功完成!找不到构建这些可选模块的必要位:_gdbm _ssl ossaudiodev
spwd
要查找必要的位,请在detect_modules()中的setup.py中查找模块的名称.
iLi*_*irt 17
我之前找到的所有答案都没有为我工作,但我最终在前面没有提到的另一个答案的帮助下解决了这个问题.这是实际的修复:https: //stackoverflow.com/a/20740964/2934226
基本上,CPPFLAGS和LDFLAGS不能在环境中设置; 你需要将它们与configure命令一起设置,如下所示:
./configure CPPFLAGS="-I[openSSL install location]/include" LDFLAGS="-L[openSSL install location]/lib" [other flags here]
Run Code Online (Sandbox Code Playgroud)
然后在编译和安装后,它工作了!
$ python3 -c "import ssl; print(ssl.OPENSSL_VERSION)"
OpenSSL 1.0.2l 25 May 2017
Run Code Online (Sandbox Code Playgroud)
以下是不起作用的事情,以及为什么:
如何使用自定义OpenSSL编译Python 3.4?没有帮助,因为你不能在环境中设置LDFLAGS,CFLAGS或CPPFLAGS; setup.py不会将它们传递给实际的编译步骤.即使设置LD_LIBRARY_PATH可能有效,您也不希望这样做,因为它很危险(请参阅http://xahlee.info/UnixResource_dir/_/ldpath.html).最后, - with-ssl不是有效的configure参数,并且在那里列出的补丁不能完全应用.
当您尝试从源代码构建内容时,拒绝链接OpenSSL的Homebrew不适用,而不是尝试获取已编译的dylib来查找重定位的库.此外,在/ usr/local中创建符号链接是危险的,并且可能导致程序针对较新的标头进行编译,但使用较旧的系统二进制文件.
如何在MacOS上使用python build包含ssl无法正常工作.编辑setup.py以添加lib和include目录,以便安装我的openSSL 部分工作,并允许您编译SSL支持.唉,它们不可导入,因为旧版本仍在使用中:
Following modules built successfully but were removed because they could not be imported:
_hashlib _ssl
Run Code Online (Sandbox Code Playgroud)
[...]
building '_ssl' extension
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -I/usr/local/opt/openssl/include/ -I./Include -I/oebuild/python/python-3.6.1/include -I. -I/usr/local/include -I/oebuild/python/src/Python-3.6.1/Include -I/oebuild/python/src/Python-3.6.1 -c /oebuild/python/src/Python-3.6.1/Modules/_ssl.c -o build/temp.macosx-10.11-x86_64-3.6/oebuild/python/src/Python-3.6.1/Modules/_ssl.o
gcc -bundle -undefined dynamic_lookup build/temp.macosx-10.11-x86_64-3.6/oebuild/python/src/Python-3.6.1/Modules/_ssl.o -L/oebuild/python/python-3.6.1/lib -L/usr/local/lib -lssl -lcrypto -o build/lib.macosx-10.11-x86_64-3.6/_ssl.cpython-36m-darwin.so
building '_hashlib' extension
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -I/usr/local/opt/openssl/include/ -I./Include -I/oebuild/python/python-3.6.1/include -I. -I/usr/local/include -I/oebuild/python/src/Python-3.6.1/Include -I/oebuild/python/src/Python-3.6.1 -c /oebuild/python/src/Python-3.6.1/Modules/_hashopenssl.c -o build/temp.macosx-10.11-x86_64-3.6/oebuild/python/src/Python-3.6.1/Modules/_hashopenssl.o
gcc -bundle -undefined dynamic_lookup build/temp.macosx-10.11-x86_64-3.6/oebuild/python/src/Python-3.6.1/Modules/_hashopenssl.o -L/oebuild/python/python-3.6.1/lib -L/usr/local/lib -lssl -lcrypto -o build/lib.macosx-10.11-x86_64-3.6/_hashlib.cpython-36m-darwin.so
*** WARNING: renaming "_ssl" since importing it failed: dlopen(build/lib.macosx-10.11-x86_64-3.6/_ssl.cpython-36m-darwin.so, 2): Symbol not found: _CRYPTO_THREADID_set_callback
Referenced from: build/lib.macosx-10.11-x86_64-3.6/_ssl.cpython-36m-darwin.so
Expected in: flat namespace
in build/lib.macosx-10.11-x86_64-3.6/_ssl.cpython-36m-darwin.so
*** WARNING: renaming "_hashlib" since importing it failed: dlopen(build/lib.macosx-10.11-x86_64-3.6/_hashlib.cpython-36m-darwin.so, 2): Symbol not found: _HMAC_CTX_copy
Referenced from: build/lib.macosx-10.11-x86_64-3.6/_hashlib.cpython-36m-darwin.so
Expected in: flat namespace
in build/lib.macosx-10.11-x86_64-3.6/_hashlib.cpython-36m-darwin.so
Run Code Online (Sandbox Code Playgroud)
otool -L 显示问题:
$ otool -L build/lib.macosx-10.11-x86_64-3.6/_ssl.cpython-36m-darwin_failed.so
build/lib.macosx-10.11-x86_64-3.6/_ssl.cpython-36m-darwin_failed.so:
/usr/lib/libssl.0.9.8.dylib (compatibility version 0.9.8, current version 0.9.8)
/usr/lib/libcrypto.0.9.8.dylib (compatibility version 0.9.8, current version 0.9.8)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)
Run Code Online (Sandbox Code Playgroud)
(CRYPTO_THREADID是在1.0.0版本中引入的,根据https://wiki.openssl.org/index.php/Manual:Threads(3)#HISTORY)
对于 Python 3.8(目前处于测试阶段),以上没有答案对我有用。
相反,对我有用的方法(2019 年 7 月):
brew install openssl
./configure --with-openssl=/usr/local/opt/openssl
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3672 次 |
| 最近记录: |