34

I have trying to run python script from the terminal but getting the next error message :

ImportError: libpython2.7.so.1.0: cannot open shared object file: No such file or directory

if I run print sys.version I get :

>>> import sys
>>> print sys.version
2.7.3 (default, Feb 26 2013, 16:27:39)
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)]

and if I run ldd /usr/local/bin/python

>> ldd /usr/local/bin/python
        linux-vdso.so.1 =>  (0x00007fff219ff000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003300c00000)
        libdl.so.2 => /lib64/libdl.so.2 (0x0000003300800000)
        libutil.so.1 => /lib64/libutil.so.1 (0x0000003310e00000)
        libm.so.6 => /lib64/libm.so.6 (0x0000003300000000)
        libc.so.6 => /lib64/libc.so.6 (0x0000003300400000)
        /lib64/ld-linux-x86-64.so.2 (0x00000032ffc00000)

I don't understand which python do I have ? why running this python script from the terminal is failing ? I have tried to run

export LD_LIBRARY_PATH=/usr/local/lib/python2.7/

with no luck...

BTW - I have managed to debug this script in eclipse with the python plug-in, and when I look at the debug configuration I see that the PYTHONPATH is set for :

/..../eclipse/plugins/org.python.pydev_3.1.0.201312121632/pysrc/pydev_sitecustomize:/..../workspace/style_checker/src:/usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg:/usr/local/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg:/usr/local/lib/python2.7:/usr/local/lib/python2.7/plat-linux2:/usr/local/lib/python2.7/lib-tk:/usr/local/lib/python2.7/lib-dynload:/usr/local/lib/python2.7/site-packages

so eclipse manage somehow to find this python2.7 libs... so how can I do it with out eclipse and from the command line ? what am I doing wrong ? using CentOS6.

yehudahs
  • 2,488
  • 8
  • 34
  • 54
  • Have you tried `export LD_LIBRARY_PATH=/usr/local/lib/python2.7/:$LD_LIBRARY_PATH`? In my case, I ran `export LD_LIBRARY_PATH=/home/minh.lengoc/.local/lib:$LD_LIBRARY_PATH` – minhle_r7 Jan 25 '14 at 09:18

7 Answers7

54

Try to find file libpython2.7.so.1.0:

locate libpython2.7.so.1.0

In my case, it show out put:

/opt/rh/python27/root/usr/lib64/libpython2.7.so.1.0

Then paste line /opt/rh/python27/root/usr/lib64 to file /etc/ld.so.conf

And run ldconfig. It solved my problem. Goodluck!

CK.Nguyen
  • 1,258
  • 17
  • 16
31

For some reason these two have worked perfectly for me:

apt-get install libpython2.7
sudo apt-get install libatlas3-base

I found them here and here

Paul Roub
  • 36,322
  • 27
  • 84
  • 93
John Kitonyo
  • 2,109
  • 1
  • 14
  • 17
3

For me, the answer at https://stackoverflow.com/a/1100297/3559967 worked. The author of that question also stated that the LD_LIBRARY_PATH approach did not work for him, but adding the library path to /etc/ld.so.conf and running ldconfig worked.

HelloWorld101
  • 3,878
  • 2
  • 34
  • 47
3

I was having a similar issue while executing a 32 bits gdb binary on a 64 bits Linux:

arm-eabi-gdb: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory

and I solved it by installing libpython2.7:i386 (note the :i386 suffix)

Clément Hurlin
  • 440
  • 3
  • 11
1

This isn't a subject I'm keen on, but my understanding is for Linux machines especially (where you're compiling python binaries) that shared library directories should be specified at the compile step.

For instance, following the linked example, here is how I ensure libpython2.7.so.1.0 is included in addition to other libraries:

./configure --enable-shared \
        --prefix=/directory/for/Python-2.7.15 \
        LDFLAGS="-Wl,--rpath=/usr/local/lib -Wl,--rpath=/directory/for/Python-2.7.15"

Notice I'm also installing python to a fixed directory of my choosing, via the --prefix option. That might not be necessary for you, but I did it to provide a solution for the general case where your python install might be located anywhere.

With the above solution, I never have to export LD_LIBRARY_PATH or mess with ldconfig

ecoe
  • 4,994
  • 7
  • 54
  • 72
1

I solved it by using "export LD_LIBRARY_PATH="${WORK_PATH}/venv/lib".

刘远圳
  • 594
  • 6
  • 5
0

Adding to the Correct answer:

Multiple question on how to the following : Then paste line /opt/rh/python27/root/usr/lib64 to file /etc/ld.so.conf

The correct way to do this add a new file in /etc/ld.so.conf.d/, and add the line above in that file.

rrpr
  • 95
  • 1
  • 1
  • 6