Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
LD_LIBRARY_路径与sudo python_Python_Environment Variables_Sudo - Fatal编程技术网

LD_LIBRARY_路径与sudo python

LD_LIBRARY_路径与sudo python,python,environment-variables,sudo,Python,Environment Variables,Sudo,我正在尝试将较新的Python(2.7.3)与旧的CentOS一起使用 我有一个将python安装到非标准位置的方法: ./configure --prefix=#{install_path} --with-threads --enable-shared --with-zlib=/usr/include make make install 我使用/etc/profile.d/设置PATH和LD\u LIBRARY\u PATH变量来查找bin/python和.so文件。这似乎大部分是有效

我正在尝试将较新的Python(2.7.3)与旧的CentOS一起使用

我有一个将python安装到非标准位置的方法:

 ./configure --prefix=#{install_path} --with-threads --enable-shared --with-zlib=/usr/include
 make
 make install
我使用
/etc/profile.d/
设置
PATH
LD\u LIBRARY\u PATH
变量来查找
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.
>>> 
[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.
>>> 
使用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.
>>> 
[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\u LIBRARY\u PATH
黑客似乎有点疯狂:

[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
/etc/sudoers
添加
默认环境保持+=“LD\u库路径”
无效

sudo-ipython
确实有效。
sudo-epython
不起作用

我很好奇我能做些什么来让
sudo
在没有
-I
的情况下选择正确的Python

相关的:

多亏了。通过在配置中链接
LDFLAGS
,您可以放弃使用
$LD\u LIBRARY\u PATH
。其中
{ldlibpath}
{install\u path}/lib

./configure --prefix=#{install_path} --with-threads --enable-shared \
--with-zlib=/usr/include LDFLAGS="-Wl,-rpath #{ldlibpath}"
正如博客文章中所指出的,在运行configure之前,您需要mkdir这个ldlibpath