为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

Smart猫小萌 2019-09-24 09:46:59
我需要在没有root访问权限的RHEL上安装几个Python模块。至少一个模块还需要访问Python.h。在这种情况下,我发现最好的方法是安装python及其依赖项~/local。它通常只能工作,但是这次Python无法构建SSL模块(请参见下面的详细信息)。这是我在做什么的痕迹。所以我下载了python 6源码,然后我去了:./configure --prefix=/home/fds/rms/localmake >& 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 sharedmakemake 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。我已经好几年没有这样做了,所以也许我忽略了某些事情。谁能解决这个问题?提前致谢。
查看完整描述

3 回答

?
喵喔喔

TA贡献1735条经验 获得超5个赞

如果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.gz

cd openssl-0.9.8g

./config

make

make 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 other

205:# socket line above, and possibly edit the SSL variable:

206:SSL=/usr/local/ssl

207:_ssl _ssl.c \

208:    -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \

209:    -L$(SSL)/lib -lssl -lcrypto

如果您在默认位置安装了OpenSSL,则只需取消注释行206-209,即可:


./configure

make

make install

然后使用以下命令验证您的安装:


python /usr/local/lib/python2.5/test/test_socket_ssl.py

test_rude_shutdown ...

test_basic ...

test_timeout ...

Modules/Setup.dist通过清除源根目录(例如make distclean)configure并make再次运行来确保获取更改。


查看完整回答
反对 回复 2019-09-24
?
慕工程0101907

TA贡献1887条经验 获得超5个赞

在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


查看完整回答
反对 回复 2019-09-24
  • 3 回答
  • 0 关注
  • 569 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信