Reputation: 11454
I'm trying to use a newer Python (2.7.3) with an old CentOS.
I have a recipe to install python to a non-standard location:
./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/
. This seems to mostly work.
With a non-root user, I get the right 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:
[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:
[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.
sudo -i python
does work.
sudo -E python
does not work.
I'm curious what I could do to get sudo
to pick up the right Python without -i
?
related:
https://stackoverflow.com/questions/12593336/odd-path-behaviour-on-centos-python
Upvotes: 0
Views: 1816
Reputation: 11454
Thanks to this blog post. You can forego the use of $LD_LIBRARY_PATH
by linking with LDFLAGS
in configure. Where #{ldlibpath}
is #{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.
Upvotes: 1