当前位置:   article > 正文

【python】Could not build the ssl module for python3.10_python3 against openssl works

python3 against openssl works


问题描述

编译python成功后,发现无法支持ssl安全模块


原因分析:

编译python时,指定的openssl找不到库,编译ssl模块过程中出错但不会导致整个编译失败,比如对于python3.10.2来说,执行如下命令

configure --prefix=/usr  --with-openssl=/usr  --with-openssl-rpath=/lib/x86_64-linux-gnu

make -j8

make install

-------------------------------------

分析  @Python-3.10.2/config.log

-------------------------------------

24063 configure:17629: result: yes
24064 configure:17778: checking for openssl/ssl.h in /usr
24065 configure:17785: result: yes
24066 configure:17801: checking whether compiling and linking against OpenSSL works
24067 Trying link with OPENSSL_LDFLAGS=-L/usr/lib; OPENSSL_LIBS=-lssl -lcrypto; OPENSSL_INCLUDES=-I/usr/include

由此可见,--with-openssl=/usr 将转化为 OPENSSL_LDFLAGS=-L/usr/lib; OPENSSL_LIBS=-lssl -lcrypto; OPENSSL_INCLUDES=-I/usr/include

其中 OPENSSL_LIBS在/usr/lib/目录下寻找 libssl.so libcrypto.so这两个库时,如果找不到将导致编译不出ssl模块

出错信息


解决方案参考:

(1)configure不带 --with-openssl等进行默认确认,但这种方法的前提是系统中有openssl并且存在/usr/lib/pkgconfig/有相关pc配置;不推荐

(2)在configure指定 --with-openssl=<path-to-openssl-dir>,这个路径下包括如下,但也是有前提,openssl安装的位置如下所示部署才可以,本问题就是采用此方案,可惜不满足如下部署,最终ssl模块未编译成功。

              <path-to-openssl-dir>/lib/libssl.so,

              <path-to-openssl-dir>/lib/libcrypto.so,

              <path-to-openssl-dir>/include/openssl/ssl.h

解决方案

针对参考方案(2)的问题,尝试将openssl编译安装部署到/usr/local/<mycode>/目录下,同时指定--with-openssl=/usr/local/<mycode>

总结

1.需求与准备

python3.10.2支持ssl模块,需要使用openssl1.1.1及以上版本

2.编译部署openssl1.1.1n

  1. ./config --prefix=/usr/local/vicode \
  2. --libdir=/lib/x86_64-linux-gnu
  3. --openssldir=/etc/ssl \
  4. -Wl,-rpath,/lib/x86_64-linux-gnu
  5. make -j1 depend
  6. make -j8
  7. make install_sw
  8. # Production Deployment For Ubuntu-16.04 Develop
  9. -- /usr/local/vicode/
  10. |-- bin/
  11. | |-- openssl.1.1.1n
  12. | |-- c_rehash.1.1.1n
  13. |-- include/
  14. | \-- openssl/
  15. \-- lib/
  16. |-- libcrypto.a
  17. |-- libcrypto.so -> libcrypto.so.1.1
  18. |-- libcrypto.so.1.1
  19. |-- libssl.a
  20. |-- libssl.so -> libssl.so.1.1
  21. \-- libssl.so.1.1
  22. # Runtime Deployment For Ubuntu-16.04 Release
  23. -- /usr/
  24. |-- bin/
  25. | |-- openssl.1.1.1n
  26. | |-- c_rehash.1.1.1n
  27. |-- include/
  28. | |-- openssl/*
  29. -- /lib/
  30. \-- x86_64-linux-gnu/
  31. |-- libssl.so.1.1
  32. |-- libcrypto.so.1.1
  33. |-- libssl.a
  34. |-- libcrypto.a
  35. |-- libssl.so
  36. |-- libcrypto.so
  37. \-- *

3.编译部署python3.10.2

  1. #注意点:自定义的openssl地址一定要放在/urs/local下,放在其他路径,也是无法找到,估计是python3的bug
  2. #注意点2:经验证 configure时加入选项参数 --libdir=/usr/lib/x86_64-linux-gnu 会导致Could not find platform dependent libraries <exec_prefix>的问题;包括ssl模块也是无法支持的
  3. #
  4. ./configure --prefix=/usr \
  5. --with-openssl-rpath=/lib/x86_64-linux-gnu \
  6. --with-openssl=/usr/local/vicode \
  7. --enable-shared
  8. make -j8 2>&1 | tee make.log
  9. make install
  10. # Release Delopyment For Ubuntu-16.04 Release
  11. -- /usr/
  12. |-- bin/
  13. | |-- 2to3
  14. | |-- idle3
  15. | |-- pip3
  16. | |-- pydoc3
  17. | |-- python3
  18. | |-- python3.10
  19. | |-- 2to3-3.10
  20. | |-- idle3.10
  21. | |-- pip3.10
  22. | |-- pydoc3.10
  23. | |-- python3-config
  24. | |-- python3.10-config
  25. |-- include/
  26. | \-- python3.10/
  27. \-- lib/
  28. |-- libpython3.10.so
  29. |-- libpython3.10.so.1.0
  30. |-- libpython3.so
  31. \-- python3.10/
  32. |-- *.py
  33. |-- */*
  34. \-- config-3.10-x86_64-linux-gnu/*
  35. # Production Deployment For Ubuntu-16.04 develop
  36. /usr/local/vicode/
  37. |-- [4.0K] bin
  38. | |-- [ 9] 2to3 -> 2to3-3.10
  39. | |-- [ 96] 2to3-3.10
  40. | |-- [6.1K] c_rehash
  41. | |-- [ 8] idle3 -> idle3.10
  42. | |-- [ 94] idle3.10
  43. | |-- [736K] openssl
  44. | |-- [ 224] pip3
  45. | |-- [ 224] pip3.10
  46. | |-- [ 9] pydoc3 -> pydoc3.10
  47. | |-- [ 79] pydoc3.10
  48. | |-- [ 10] python3 -> python3.10
  49. | |-- [ 17] python3-config -> python3.10-config
  50. | |-- [ 16K] python3.10
  51. | `-- [3.0K] python3.10-config
  52. |-- [4.0K] include
  53. | |-- [4.0K] openssl
  54. | `-- [4.0K] python3.10
  55. |-- [1.1K] install-openssl
  56. |-- [3.0K] install-python
  57. |-- [4.0K] lib
  58. | |-- [5.4M] libcrypto.a
  59. | |-- [ 16] libcrypto.so -> libcrypto.so.1.1
  60. | |-- [3.2M] libcrypto.so.1.1
  61. | |-- [ 20] libpython3.10.so -> libpython3.10.so.1.0
  62. | |-- [ 18M] libpython3.10.so.1.0
  63. | |-- [7.5K] libpython3.so
  64. | |-- [1007K] libssl.a
  65. | |-- [ 13] libssl.so -> libssl.so.1.1
  66. | |-- [674K] libssl.so.1.1
  67. | |-- [4.0K] python3.10
  68. | `-- [4.0K] x86_64-linux-gnu
  69. `-- [4.0K] share
  70. `-- [4.0K] man

4.验证是否支持ssl模块

  1. #
  2. # Failure : not support for ssl module
  3. #
  4. root@P328:.#
  5. root@P328:.# python3.10 -c 'import ssl'
  6. Could not find platform dependent libraries <exec_prefix>
  7. Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
  8. Traceback (most recent call last):
  9. File "<string>", line 1, in <module>
  10. File "/usr/local/vicode/lib/python3.10/ssl.py", line 98, in <module>
  11. import _ssl # if we can't import it, let the error propagate
  12. ModuleNotFoundError: No module named '_ssl'
  13. root@P328:.#
  14. #
  15. # Success: not support for ssl module
  16. #
  17. root@P328:.#
  18. root@P328:.# python3.10 -c 'import ssl'
  19. root@P328:.#

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/704542
推荐阅读
相关标签
  

闽ICP备14008679号