title: LD_LIBRARY_PATH with sudo python
body: <p>I'm trying to use a newer Python (2.7.3) with an old CentOS.</p>
  
  <p>I have a recipe to install python to a non-standard location:</p>
  
  <pre><code> ./configure --prefix=#{install_path} --with-threads --enable-shared --with-zlib=/usr/include
   make
   make install
  </code></pre>
  
  <p>I set the <code>PATH</code> and <code>LD_LIBRARY_PATH</code> variables to find <code>bin/python</code> and the <code>.so</code> files using <code>/etc/profile.d/</code>. This seems to mostly work. </p>
  
  <p>With a non-root user, I get the right Python:</p>
  
  <pre><code>[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.
  &gt;&gt;&gt; 
  </code></pre>
  
  <p>With a root user, I get the right Python:</p>
  
  <pre><code>[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.
  &gt;&gt;&gt; 
  </code></pre>
  
  <p>However, the <code>$LD_LIBRARY_PATH</code> hack seems to be a little wonked when using sudo:</p>
  
  <pre><code>[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
  </code></pre>
  
  <p>Even though the variables look right:</p>
  
  <pre><code>[vagrant@localhost ~]$ sudo which python
  /opt/Python-2.7.3/bin/python
  </code></pre>
  
  <p>Adding <code>Defaults env_keep += "LD_LIBRARY_PATH"</code> to <code>/etc/sudoers</code> does not work.</p>
  
  <p><code>sudo -i python</code> does work.
  <code>sudo -E python</code> does not work.</p>
  
  <p>I'm curious what I could do to get <code>sudo</code> to pick up the right Python without <code>-i</code>?</p>
  
  <p>related:</p>
  
  <p><a href="https://stackoverflow.com/questions/257616/sudo-changes-path-why">sudo changes PATH - why?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/12593336/odd-path-behaviour-on-centos-python">https://stackoverflow.com/questions/12593336/odd-path-behaviour-on-centos-python</a></p>