猿问

在非标准位置使用SSL支持构建Python

我需要在没有root访问权限的RHEL上安装几个Python模块。至少一个模块还需要访问Python.h。


在这种情况下,我发现最好的方法是安装python及其依赖项~/local。它通常只能工作,但是这次Python无法构建SSL模块(请参见下面的详细信息)。这是我在做什么的痕迹。


所以我下载了python 6源码,然后我去了:


./configure --prefix=/home/fds/rms/local

make >& make.log

日志检查显示ssl模块尚未编译,但未提及原因(make或configure中没有其他发生ssl的事件):


Failed to find the necessary bits to build these modules:

_bsddb             _curses            _curses_panel

_hashlib           _sqlite3           _ssl   <----------

因此,我认为python根本找不到任何ssl库(这很奇怪,但是...)。所以我下载了openssl-0.9.8r和


./config --prefix=/home/fds/rms/local shared

make

make install

现在回到Python,我重新配置。它失败,但是这次有所不同:


Failed to build these modules:

_hashlib           _ssl

仔细查看日志文件可以发现:


gcc -pthread -shared build/temp.linux-x86_64-2.6/home/fds/rms/installers/Python-2.6.6/Modules/_ssl.o -L/home/fds/rms/local/lib -L/usr/local/lib -lssl -lcrypto -o build/lib.linux-x86_64-2.6/_ssl.so

*** WARNING: renaming "_ssl" since importing it failed: libssl.so.0.9.8: cannot open shared object file: No such file or directory

因此,现在它选择的是库,但并没有完全正确(文件应该在应有的位置):


$ find /home/fds/rms/local -iname libssl.so.0.9.8

/home/fds/rms/local/lib/libssl.so.0.9.8

嗯,它到了所有错误的地方。我尝试给出一个提示:


CPPFLAGS="-I/home/fds/rms/local/include -I/home/fds/rms/local/include/openssl" LDFLAGS="-L/home/fds/rms/local/lib" ./configure --prefix=/home/fds/rms/local

但是什么都没有改变,make似乎根本没有尝试/home/fds/rms/local/lib。


我已经好几年没有这样做了,所以也许我忽略了某些事情。谁能解决这个问题?


提前致谢。


Smart猫小萌
浏览 570回答 3
3回答

喵喔喔

如果Modules/Setup.distOpenSSL不在标准位置,则需要进行编辑以指定其位置。从在Python 2.5.1中获得SSL支持:如果您发现自己的Linux框需要python的ssl支持(以在诸如httplib.HTTPSConnection或imaplib.IMAP4_SSL之类的客户端中使用客户端),那么让我为您节省几个小时的网上搜索(当然,如果您有找到这个,则意味着您已经完成了一些关卡搜寻!)。如果收到以下异常消息,您将知道是否需要将ssl支持编译到python安装中:AttributeError:'module'对象没有属性'ssl'为了使它消失,以便您可以继续愉快地悬吊python代码,首先需要确保已安装OpenSSL。默认情况下,它是从/ usr / local / ssl的源代码安装的如果该目录不存在,请获取源包。执行标准:tar zxf openssl-0.9.8g.tar.gzcd openssl-0.9.8g./configmakemake install然后获取2.5.1和以下版本的python源:tar zxf Python-2.5.1.tgz && cd Python-2.5.1然后,您需要编辑Modules / Setup.dist:204:# Socket module helper for SSL support; you must comment out the other205:# socket line above, and possibly edit the SSL variable:206:SSL=/usr/local/ssl207:_ssl _ssl.c \208:&nbsp; &nbsp; -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \209:&nbsp; &nbsp; -L$(SSL)/lib -lssl -lcrypto如果您在默认位置安装了OpenSSL,则只需取消注释行206-209,即可:./configuremakemake install然后使用以下命令验证您的安装:python /usr/local/lib/python2.5/test/test_socket_ssl.pytest_rude_shutdown ...test_basic ...test_timeout ...Modules/Setup.dist通过清除源根目录(例如make distclean)configure并make再次运行来确保获取更改。

慕工程0101907

在Bourne Shell(/ bin / sh或/ bin / bash)中:$ LD_LIBRARY_PATH=/usr/local/lib$ export LD_LIBRARY_PATH$ make在C-shell(/ bin / csh或/ bin / tcsh)中:% setenv LD_LIBRARY_PATH /usr/local/lib% make
随时随地看视频慕课网APP

相关分类

Python
我要回答