在非标准位置构建具有SSL支持的Python [英] Building Python with SSL support in non-standard location

查看:1136
本文介绍了在非标准位置构建具有SSL支持的Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



在这种情况下,我发现最好的事情是安装python和它的依赖项在〜/ local 。它通常只是工作,但这次Python无法构建SSL模块(见下面的细节)。



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

  ./ configure --prefix = / home / fds / rms / local 
make>& make.log

检查日志显示ssl模块尚未编译,但没有提到的原因(在make或configure中没有其他ssl出现):

 无法找到构建这些模块所需的位: 
_bsddb _curses _curses_panel
_hashlib _sqlite3 _ssl <----------

所以我想,python没有找到任何ssl库(这是奇怪,但嘿...)。所以我下载openssl-0.9.8r和

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

现在回到Python,我./configure和make再次。它失败了,但这一次是不同的:

 无法构建这些模块:
_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 
***警告:重命名_ssl导入失败:libssl .so.0.9.8:无法打开共享对象文件:没有这样的文件或目录

(文件在那里应该是):

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

接下来是跟踪make,看看它在哪里寻找文件:

  $ strace -f make 2>& 1 | grep libssl.so.0.9.8 
[pid 5584] open(/ lib / libssl.so.0.9.8,O_RDONLY)= -1 ENOENT(无此文件或目录)
[pid 5584] open(/ usr / lib / libssl.so.0.9.8,O_RDONLY)= -1 ENOENT(无此文件或目录)
[pid 5584] open(/ lib64 / tls / x86_64 /
[pid 5584] open(/ lib64 / tls / libssl.so.0.9.8,O_RDONLY)=$ libxls.so.0.9.8,O_RDONLY)= -1 ENOENT(没有这样的文件或目录) -1 ENOENT(没有这样的文件或目录)
[pid 5584] open(/ lib64 / x86_64 / libssl.so.0.9.8,O_RDONLY)= -1 ENOENT $ b [pid 5584] open(/ lib64 / libssl.so.0.9.8,O_RDONLY)= -1 ENOENT(无此文件或目录)
[pid 5584] open(/ usr / lib64 / tls / x86_64 / libssl.so.0.9.8,O_RDONLY)= -1 ENOENT(无此文件或目录)
[pid 5584] open(/ usr / lib64 / tls / libssl.so.0.9。 8,O_RDONLY)= -1 ENOENT(无此文件或目录)
[pid 5584] open(/ usr / lib64 / x86_64 / libssl.so.0.9.8,O_RDONLY)= -1 ENOENT没有这样的文件或目录)
[pid 5584] open(/ usr / lib64 / libssl.so.0.9.8,O_RDONLY)= -1 ENOENT(没有这样的文件或目录)
[pid 5584] write(1,***警告:重命名\_ssl\sin...,131 ***警告:重命名_ssl,因为导入失败:libssl.so.0.9.8:can not打开共享对象文件:没有这样的文件或目录
[pid 5584] open(/ lib / libssl.so.0.9.8,O_RDONLY)= -1 ENOENT [pid 5584] open(/ usr / lib / libssl.so.0.9.8,O_RDONLY)= -1 ENOENT(没有这样的文件或目录)
[pid 5584] open(/ lib64 / libssl。
[pid 5584] open(/ usr / lib64 / tls / libssl.so.0.9.8,O_RDONLY)=ENOENT -1 ENOENT(没有这样的文件或目录)
[pid 5584] open(/ usr / lib64 / libssl.so.0.9.8,O_RDONLY)= -1 ENOENT $ b [pid 5584] write(1,***警告:重命名\_hashlib \...,135 ***警告:重命名_hashlib导入失败:libssl.so.0.9。 8:无法打开共享对象文件:没有这样的文件或目录

Mhhh,地方。我尝试提供一个提示:

  CPPFLAGS = -  I / home / fds / rms / local / include -I / home / fds / rms / local / include / opensslLDFLAGS = -  L / home / fds / rms / local / lib./configure --prefix = / home / fds / rms / local 

但没有任何变化, make 似乎没有尝试 / home / fds / rms / local / lib



我已经多年没有这样做,俯瞰的东西。任何人都可以帮助解决这个问题?



提前感谢。

解决方案

如果不在标准位置,您需要编辑 Modules / Setup.dist 以指定OpenSSL的位置。从在Python 2.5.1中获取SSL支持


如果你发现自己在linux上需要ssl支持在python(到
使用客户端在类似httplib.HTTPSConnection或
imaplib.IMAP4_SSL),然后让我保存你在网上狩猎
几个小时(当然如果你发现这意味着
你已经做了一些级别的狩猎) 。



如果您得到以下异常消息,您将知道是否需要将ssl支持编译到python
安装中:
AttributeError:'module '对象没有属性'ssl'



为了使它消失,你可以继续愉快地甩尾
python代码,你需要先make请确保您已安装OpenSSL
。默认情况下,它从源安装在:/ usr / local / ssl



如果该目录不存在,请抓取源包。



执行标准:

  tar zxf openssl-0.9.8g.tar.gz 
cd openssl-0.9.8g
./config
make
make install

然后获取python源码为2.5.1和:tar zxf Python-2.5.1.tgz
&& cd Python-2.5.1



然后你需要编辑Modules / Setup.dist:

  204:#Socket模块帮助器支持SSL;您必须注释掉上面的其他
205:#套接字行,并可能编辑SSL变量:
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行, p>

  ./ configure 
make
make install

然后使用以下方式验证您的安装:

  python / usr / local /lib/python2.5/test/test_socket_ssl.py 
test_rude_shutdown ...
test_basic ...
test_timeout ...



I need to install several Python modules on a RHEL where I don't have root access. At least one of the modules also needs access to Python.h.

In this case I find that the best thing is to install python and it dependencies in ~/local. It usually just works, but this time Python fails to build the SSL module (see details below). Here's the trace of what I'm doing.

So I downloaded python 6 source and off I went:

./configure --prefix=/home/fds/rms/local
make >& make.log

An inspection to log reveals that ssl module has not been compiled, but there is no mention of the cause (no other occurence of ssl in make or configure):

Failed to find the necessary bits to build these modules:
_bsddb             _curses            _curses_panel
_hashlib           _sqlite3           _ssl   <----------

So I figure, python is not finding any ssl library at all (which is strange, but hey...). So I download openssl-0.9.8r and

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

Now back to Python, I ./configure and make again. It fails, but this time it's different:

Failed to build these modules:
_hashlib           _ssl

A closer inspection to the log file reveals this:

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

So now it's picking up the library but not quite getting it right (the file is there where is should be):

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

Next thing is tracing make and see where is it looking for the file:

$ strace -f make 2>&1 | grep libssl.so.0.9.8
[pid  5584] open("/lib/libssl.so.0.9.8", O_RDONLY) = -1 ENOENT (No such file or directory)
[pid  5584] open("/usr/lib/libssl.so.0.9.8", O_RDONLY) = -1 ENOENT (No such file or directory)
[pid  5584] open("/lib64/tls/x86_64/libssl.so.0.9.8", O_RDONLY) = -1 ENOENT (No such file or directory)
[pid  5584] open("/lib64/tls/libssl.so.0.9.8", O_RDONLY) = -1 ENOENT (No such file or directory)
[pid  5584] open("/lib64/x86_64/libssl.so.0.9.8", O_RDONLY) = -1 ENOENT (No such file or   directory)
[pid  5584] open("/lib64/libssl.so.0.9.8", O_RDONLY) = -1 ENOENT (No such file or directory)
[pid  5584] open("/usr/lib64/tls/x86_64/libssl.so.0.9.8", O_RDONLY) = -1 ENOENT (No such file or directory)
[pid  5584] open("/usr/lib64/tls/libssl.so.0.9.8", O_RDONLY) = -1 ENOENT (No such file or directory)
[pid  5584] open("/usr/lib64/x86_64/libssl.so.0.9.8", O_RDONLY) = -1 ENOENT (No such file or directory)
[pid  5584] open("/usr/lib64/libssl.so.0.9.8", O_RDONLY) = -1 ENOENT (No such file or directory)
[pid  5584] write(1, "*** WARNING: renaming \"_ssl\" sin"..., 131*** WARNING: renaming "_ssl" since importing it failed: libssl.so.0.9.8: cannot open shared object file: No such file or directory
[pid  5584] open("/lib/libssl.so.0.9.8", O_RDONLY) = -1 ENOENT (No such file or directory)
[pid  5584] open("/usr/lib/libssl.so.0.9.8", O_RDONLY) = -1 ENOENT (No such file or directory)
[pid  5584] open("/lib64/libssl.so.0.9.8", O_RDONLY) = -1 ENOENT (No such file or directory)
[pid  5584] open("/usr/lib64/tls/libssl.so.0.9.8", O_RDONLY) = -1 ENOENT (No such file or directory)
[pid  5584] open("/usr/lib64/libssl.so.0.9.8", O_RDONLY) = -1 ENOENT (No such file or directory)
[pid  5584] write(1, "*** WARNING: renaming \"_hashlib\""..., 135*** WARNING: renaming "_hashlib" since importing it failed: libssl.so.0.9.8: cannot open shared object file: No such file or directory

Mhhh, it's looking in all the wrong places. I try to give a hint:

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

But nothing changes, and make does not seem to try /home/fds/rms/local/lib at all.

I haven't done this in years, so maybe I'm overlooking something. Can anyone help with the problem?

Thanks in advance.

解决方案

You need to edit Modules/Setup.dist to specify the location of OpenSSL if it is not in the standard location. From Getting SSL Support in Python 2.5.1:

If you find yourself on a linux box needing ssl support in python (to use a client in things like httplib.HTTPSConnection or imaplib.IMAP4_SSL), then let me save you a couple of hours of hunting around the web (of course if you have found this then that means you've done some level hunting already!).

You'll know if you need ssl support compiled into your python installation if you get the following exception message: AttributeError: 'module' object has no attribute 'ssl'

In order to make that go away so you can continue happily slinging python code, you'll need to first make sure you have OpenSSL installed. By default it is installed from source at: /usr/local/ssl

If that directory doesn't exist, then grab the source package.

Do the standard:

tar zxf openssl-0.9.8g.tar.gz
cd openssl-0.9.8g
./config
make
make install

Then grab the python sources for 2.5.1 and: tar zxf Python-2.5.1.tgz && cd Python-2.5.1

Then you need to edit the 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

If you installed OpenSSL in the default locations you can just uncomment lines 206-209, then:

./configure
make
make install

Then verify your installation with:

python /usr/local/lib/python2.5/test/test_socket_ssl.py
test_rude_shutdown ...
test_basic ...
test_timeout ...

这篇关于在非标准位置构建具有SSL支持的Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆