重要错误:没有名为“ss”的模块

2024-06-16 08:44:50 发布

您现在位置:Python中文网/ 问答频道 /正文

Ubuntu Maverick w/Python 2.7版本:

我无法确定如何解决以下导入错误:

>>> import ssl
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/ssl.py", line 60, in <module>
   import _ssl             # if we can't import it, let the error propagate
ImportError: No module named _ssl

更新: 我重新编译了源代码。我不知道如何添加--with ssl选项下面提到的答案,而是通过编辑/Modules/Setup.dist中有关ssl的行来实现这一点


Tags: inimport版本sslmostubuntu错误line
3条回答

与最初的问题无关,但因为这是谷歌的第一个结果。。。我在Google AppEngine上点击了这个,并且不得不添加:

libraries:
- name: ssl
  version: latest

每个:https://cloud.google.com/appengine/docs/python/sockets/ssl_support

请注意:这似乎适用于Python2.7.9版本,但不适用于2.7.10或2.7.11。

如果您从源代码构建Python,这只是一个依赖关系问题:由于您没有安装OpenSSL lib,Python在安装ssl模块时会自动失败。您可以在make命令的最终报告中看到它:

Python build finished, but the necessary bits to build these modules were not found:
_bsddb             _sqlite3           _ssl
_tkinter           bsddb185           dbm
dl                 gdbm               imageop
sunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the module's name.

在任何标准的lib路径(/usr/lib/usr/local/lib…)中安装OpenSSL lib就可以了。不管怎样,我就是这样做的:-)

您是从源代码构建Python的吗?如果是,则在构建时需要--with-ssl选项。

相关问题 更多 >