Fix Python – Python executable not finding libpython shared library


Asked By – sans

I am installing Python 2.7 on CentOS 5. I built and installed Python as follows

./configure --enable-shared --prefix=/usr/local
make install

When I try to run /usr/local/bin/python, I get this error message

/usr/local/bin/python: error while loading shared libraries: cannot open shared object file: No such file or directory

When I run ldd on /usr/local/bin/python, I get

ldd /usr/local/bin/python => not found => /lib64/ (0x00000030e9a00000) => /lib64/ (0x00000030e9200000) => /lib64/ (0x00000030fa200000) => /lib64/ (0x00000030e9600000) => /lib64/ (0x00000030e8e00000)
    /lib64/ (0x00000030e8a00000)

How do I tell Python where to find libpython?

Now we will see solution for issue: Python executable not finding libpython shared library


Try the following:

LD_LIBRARY_PATH=/usr/local/lib /usr/local/bin/python

Replace /usr/local/lib with the folder where you have installed if it is not in /usr/local/lib.

If this works and you want to make the changes permanent, you have two options:

  1. Add export LD_LIBRARY_PATH=/usr/local/lib to your .profile in your home directory (this works only if you are using a shell which loads this file when a new shell instance is started). This setting will affect your user only.

  2. Add /usr/local/lib to /etc/ and run ldconfig. This is a system-wide setting of course.

This question is answered By – Tamás

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0