如何在OSX上安装Python SSL模块?

4 投票
3 回答
5365 浏览
提问于 2025-04-16 00:12

当我部署我的谷歌应用引擎项目时,出现了以下警告:

WARNING appengine_rpc.py:399 ssl module not found.
Without the ssl module, the identity of the remote host cannot be verified, and
connections may NOT be secure. To fix this, please install the ssl module from
http://pypi.python.org/pypi/ssl.

我下载了这个包,但当我尝试

python setup.py build

时,出现了以下错误信息:

looking for /usr/include/openssl/ssl.h
looking for /usr/local/ssl/include/openssl/ssl.h
looking for /usr/contrib/ssl/include/openssl/ssl.h
Traceback (most recent call last):
  File "setup.py", line 167, in <module>
    ssl_incs, ssl_libs, libs = find_ssl()
  File "setup.py", line 142, in find_ssl
    raise Exception("No SSL support found")
Exception: No SSL support found

我需要做些什么才能安装它,是路径的问题还是别的什么?

3 个回答

0

你可能需要手动安装openssl,虽然默认情况下,Xcode安装时会把相关的头文件放在/usr/include这个文件夹里。(如果你还没有安装Xcode,那么你的电脑上可能也没有gcc这个工具,后面的构建过程也可能会失败。)

2

在10.5和10.6版本的苹果自带Python中,包含了ssl模块(对于更早的版本不太清楚):

Python 2.6.5 (r265:79359, Mar 24 2010, 01:32:55) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>> ssl.__file__
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ssl.pyc'

(来自10.5.8)

即使你有ssl模块,你也可能会从appengine_rpc.py中看到那个错误信息——你需要确保你的GAE下载包含了:

/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/cacerts/cacerts.txt

如果你有这两样东西,试着执行:

import google.appengine.tools.https_wrapper

这应该能在苹果自带的Python上正常工作,但如果不行,错误信息可能会更有帮助。如果你安装了多个Python版本,导致其中一个影响了GAE,记得在GAE中使用Python路径设置,指向苹果自带的Python。

5

通过先安装pycrypto来解决这个问题,具体步骤可以参考这里的说明,同时也借鉴了对这个问题的回答中的一些见解。

我最终构建时使用的完整命令行是:

CC='/usr/bin/gcc-4.0' python2.5 setup.py build

撰写回答