简体   繁体   English

LD_LIBRARY_PATH与sudo python

[英]LD_LIBRARY_PATH with sudo python

I'm trying to use a newer Python (2.7.3) with an old CentOS. 我正尝试在旧的CentOS上使用更新的Python(2.7.3)。

I have a recipe to install python to a non-standard location: 我有一个将python安装到非标准位置的方法:

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

I set the PATH and LD_LIBRARY_PATH variables to find bin/python and the .so files using /etc/profile.d/ . 我设置了PATHLD_LIBRARY_PATH变量,以使用/etc/profile.d/查找bin/python.so文件。 This seems to mostly work. 这似乎主要起作用。

With a non-root user, I get the right Python: 使用非root用户,我得到了正确的Python:

[vagrant@localhost ~]$ 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.
>>> 

With a root user, I get the right Python: 使用root用户,我得到了正确的Python:

[vagrant@localhost ~]$ sudo su
[root@localhost 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.
>>> 

However, the $LD_LIBRARY_PATH hack seems to be a little wonked when using sudo: 但是,使用sudo时, $LD_LIBRARY_PATH hack似乎有点奇怪:

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

Even though the variables look right: 即使变量看起来正确:

[vagrant@localhost ~]$ sudo which python
/opt/Python-2.7.3/bin/python

Adding Defaults env_keep += "LD_LIBRARY_PATH" to /etc/sudoers does not work. Defaults env_keep += "LD_LIBRARY_PATH"/etc/sudoers无效。

sudo -i python does work. sudo -i python确实可以工作。 sudo -E python does not work. sudo -E python不起作用。

I'm curious what I could do to get sudo to pick up the right Python without -i ? 我很好奇如何使sudo在不使用-i情况下获取正确的Python?

related: 有关:

sudo changes PATH - why? sudo更改PATH-为什么?

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

Thanks to this blog post . 感谢这篇博客文章 You can forego the use of $LD_LIBRARY_PATH by linking with LDFLAGS in configure. 您可以通过在configure中链接LDFLAGS来放弃$LD_LIBRARY_PATH的使用。 Where #{ldlibpath} is #{install_path}/lib : 其中#{ldlibpath}#{install_path}/lib

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

As noted in the blog post, you will need to mkdir this ldlibpath before running configure. 如博客文章中所述,在运行configure之前,您需要mkdir此ldlibpath。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM