簡體   English   中英

LD_LIBRARY_PATH與sudo python

[英]LD_LIBRARY_PATH with sudo python

我正嘗試在舊的CentOS上使用更新的Python(2.7.3)。

我有一個將python安裝到非標准位置的方法:

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

我設置了PATHLD_LIBRARY_PATH變量,以使用/etc/profile.d/查找bin/python.so文件。 這似乎主要起作用。

使用非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.
>>> 

使用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.
>>> 

但是,使用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

即使變量看起來正確:

[vagrant@localhost ~]$ 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在不使用-i情況下獲取正確的Python?

有關:

sudo更改PATH-為什么?

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

感謝這篇博客文章 您可以通過在configure中鏈接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。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM