toby

mac下编译openssl以及python

最近学习python的模块,发现引用httplibHTTPConnection方法时,报AttributeError: 'module' object has no attribute 'HTTPConnection'的错误,google了一下发现httplib模块需要依赖ssl,这里:http://paltman.com/2007/11/15/getting-ssl-support-in-python-251/详细了介绍了openssl的下载安装编译,以及怎么重新编译python,按照作者的指引,成功编译了openssl,但是到编译python的时候就有问题了,报错如下:

  ignoring file /usr/local/ssl/lib/libcrypto.a, file was built for archive which is not the architecture being linked (x86_64)

重新注释掉Setup.dist里面的ssl模块,再编译python发现编译成功,看来是ssl的问题呀.

回头又看了一遍traceback的错误,发现了x86_64的字眼,难道是ssl编译版本的问题?把ssl又弄出来重新编译了一次,发现执行./config的时候提示如下:

    WARNING! If you wish to build 64-bit library, then you have to
             invoke './Configure darwin64-x86_64-cc' *manually*.
             You have about 5 seconds to press Ctrl-C to abort.

你妹的,原来默认编译是32位的!执行命令:

    ./Configure darwin64-x86_64-cc
    make
    make install

然后用命令lipo -info libssl.a查看一下ssl的信息,显示

    Non-fat file: libssl.a is architecture: x86_64`

恩,这下是64位版本了,然后重新编译了一遍python,问题终于解决了.其实,要是早点发现我mac上面的python是64位的,就没有上面这个问题了...

附:查看py是32位还是64位的方法:

  import struct
  print struct.calcsize("P") * 8 #显示64则为64位

参考: http://paltman.com/2007/11/15/getting-ssl-support-in-python-251/
http://stackoverflow.com/questions/4084210/how-do-i-build-openssl-as-32-bit-i386-on-mac-os-x