【发布时间】:2012-12-24 22:34:47
【问题描述】:
我正在尝试将更新的 Python (2.7.3) 与旧的 CentOS 一起使用。
我有一个将 python 安装到非标准位置的方法:
./configure --prefix=#{install_path} --with-threads --enable-shared --with-zlib=/usr/include
make
make install
我设置了PATH 和LD_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.
>>>
然而,$LD_LIBRARY_PATH hack 在使用 sudo 时似乎有点奇怪:
[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 不起作用。
我很好奇在没有-i 的情况下如何让sudo 选择正确的Python?
相关:
https://stackoverflow.com/questions/12593336/odd-path-behaviour-on-centos-python
【问题讨论】:
标签: python environment-variables sudo