无法在 python3.6 中导入 ssl: ModuleNotFoundError: No module named '_ssl'

use*_*654 6 python ssl openssl python-import python-3.x

我从源代码安装了 python 3.6。Python 似乎工作正常,但我无法导入 openssl 1.1.1(我需要使用的预发行版)。我认为存在路径问题但不确定。当我尝试从 python 导入 ssl 时,这是我得到的输出:

~/Downloads/Python-3.6.5$ python3
Python 3.6.5 (default, May  9 2018, 15:43:39) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/ssl.py", line 101, in <module>
    import _ssl             # if we can't import it, let the error propagate
ModuleNotFoundError: No module named '_ssl' 
Run Code Online (Sandbox Code Playgroud)

有什么建议?

当我安装 openssl 时,我抓取了源代码

./config
sudo make
sudo make install 
Run Code Online (Sandbox Code Playgroud)

看来openssl已经正确安装了。输出大部分类似于此路径:

/usr/local/share/man/man5/config.5
Run Code Online (Sandbox Code Playgroud)

然后我然后取消注释这两行 Python-3.6.5/Module/Setup.dist

_socket socketmodule.c
Run Code Online (Sandbox Code Playgroud)

# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:

SSL=/usr/local/ssl
_ssl _ssl.c \
    -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
    -L$(SSL)/lib -lssl -lcrypto
Run Code Online (Sandbox Code Playgroud)

然后,当我尝试在 python 中导入 ssl 时,出现此错误:

Python 3.6.5 (default, May  9 2018, 15:43:39) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/ssl.py", line 101, in <module>
    import _ssl             # if we can't import it, let the error propagate
ModuleNotFoundError: No module named '_ssl'
Run Code Online (Sandbox Code Playgroud)

你能帮忙吗?问题的原因是什么?