2012-12-24 75 views
0

我想用一个较旧的Python(2.7.3)与旧的CentOS。LD_LIBRARY_PATH与sudo python

我有一个配方安装Python到一个非标准的位置:

./configure --prefix=#{install_path} --with-threads --enable-shared --with-zlib=/usr/include 
make 
make install 

我设置了PATHLD_LIBRARY_PATH变量找到bin/python和使用/etc/profile.d/.so文件。这似乎主要是工作。

对于非root用户,我得到正确的Python:

[[email protected] ~]$ python 
Python 2.7.3 (default, Dec 24 2012, 15:18:59) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2 
Type "help", "copyright", "credits" or "license" for more information. 
>>> 

用root用户,我得到正确的Python:

[[email protected] ~]$ sudo su 
[[email protected] vagrant]# python 
Python 2.7.3 (default, Dec 24 2012, 15:18:59) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2 
Type "help", "copyright", "credits" or "license" for more information. 
>>> 

然而,$LD_LIBRARY_PATH黑客似乎是

[[email protected] ~]$ sudo python 
python: error while loading shared libraries: libpython2.7.so.1.0: 
cannot open shared object file: No such file or directory 

即使变量看的权利:使用sudo的时候有点wonked

[[email protected] ~]$ sudo which python 
/opt/Python-2.7.3/bin/python 

添加Defaults env_keep += "LD_LIBRARY_PATH"/etc/sudoers不起作用。

sudo -i python确实有效。 sudo -E python不起作用。

我很好奇我能做些什么来让sudo拿起正确的Python而没有-i

相关:

sudo changes PATH - why?

https://stackoverflow.com/questions/12593336/odd-path-behaviour-on-centos-python

回答

1

感谢this blog post。你可以在配置中通过链接LDFLAGS来放弃使用$LD_LIBRARY_PATH。其中#{ldlibpath}#{install_path}/lib

./configure --prefix=#{install_path} --with-threads --enable-shared \ 
--with-zlib=/usr/include LDFLAGS="-Wl,-rpath #{ldlibpath}" 

由于在博客文章中指出,需要在运行configure之前的mkdir这个ldlibpath。