`

uwsgi python ssl编译问题记录

 
阅读更多
uwsgi python ssl编译问题记录
发表于6个月前(2013-12-10 10:54)   阅读(187) | 评论(0) 2人收藏此文章, 我要收藏
赞0
python uwsgi ssl compile

昨天,因为在运行gevent时说ssl没找到,是因为缺省编译python 2.7.6时没带ssl的编译。那么为什么没带呢?主要原因是python没找到。因为我是把相关的软件都安装在用户目录下,所以缺省的位置是根本找不到的。于是在网上搜了一下如何编译时,将ssl编译进去,找了半天的结果基本上都是要修改Modules/Setup.dist下有关ssl的内容,好象没有通过设置环境变量就可以解决的方法,于是乎只能修改这个文件,大约修改是这样的:

SSL=/home/ap/xxxx
_ssl _ssl.c \
        -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
        -L$(SSL)/lib64 -lssl -lcrypto
一个是把上面的 SSL 的路径改为我的用户目录,另一个是把 -L的路径改为lib64,因为我的环境是x86_64的,所以openssl是放在$HOME/lib64下的。

make的时候说 Modules/Setup.dist 比 Modules/Setup 要新,于是我覆盖了一下。make之后还是说 _ssl 没找到:

Python build finished, but the necessary bits to build these modules were not found:
_bsddb _curses _curses_panel
_sqlite3 _ssl _tkinter
bsddb185 bz2 dbm
dl gdbm imageop
readline sunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
可以看到最后一行有个建议,说是看一下setup.py是如何检查模块的。

于是我编译setup.py首先在501左或添加了一行:

inc_dirs = self.compiler.include_dirs[:]
    lib_dirs = self.compiler.library_dirs[:]
    lib_dirs.append('/home/ap/xxxx/lib64')
最后一行是我加的,把lib的目录加进去了。然后又在844行左右,加了一行:

if have_any_openssl:
    if have_usable_openssl:
        ssl_libs.append('/home/ap/xxxx/lib64')
        # The _hashlib module wraps optimized implementations
        # of hash functions from the OpenSSL library.
ssl_libs.append('/home/ap/xxxx/lib64') 这一行。

然后再编译就成功了。再执行make install来安装到用户目录下。进入python环境, import ssl就正确了。

但是,我再编译uwsgi时发现了问题。在编译最后报错了:

/home/ap/xxxx/src/packages/build/Python-2.7.6/./Modules/_ssl.c:1280: undefined reference to `SSL_get_error'
/home/ap/xxxx/lib/python2.7/config/libpython2.7.a(_ssl.o): In function `_ssl_threadid_callback':
/home/ap/xxxx/src/packages/build/Python-2.7.6/./Modules/_ssl.c:1661: undefined reference to `CRYPTO_THREADID_set_numeric'
collect2: ld returned 1 exit status
网上查了查,原来是 -lssl 没自动加进去。但是为什么没自动加进去呢?还是因为我把openssl装到了用户目录下。于是经过试验,可以在编译时添加一些环境变量来解决这一问题,编译命令如下:

LDFLAGS="-L$HOME/lib64" UWSGI_INCLUDES=$HOME/include python uwsgiconfig.py --build
这回就正确了。然后把编译好的uwsgi拷贝到你想放的地方,比如$HOME/bin下。

如果一些包不在常见的目录下,编译的确是件麻烦的事。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics