python: error while loading shared libraries: libpython3.4m.so.1.0: cannot open shared object file: No such file or directory

106,032

Solution 1

Try adding the python3.4's lib path to the $LD_LIBRARY_PATH environment variable.

First find out the lib path of python3.4 (depends on how you installed python3.4)

For me it was: /opt/python361/lib, then add it to environment variable like so:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/python361/lib

P.S. I came across a similar problem while using virtualenv with python3.6, and I fixed it like so:

  • First, append include <lib path of python3.x> to /etc/ld.so.conf (Something like: include /opt/python361/lib or include /usr/local/lib)
  • Then, activate the new configuration by running sudo /sbin/ldconfig -v.

Solution 2

Another way is adding LDFLAGS="-Wl,-rpath /usr/local/lib" in configure, for example

./configure --prefix=/usr/local --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"

/usr/local/lib is the path where libpython3.*.so files are in

Solution 3

For Python 3.6, it was fixed by

sudo apt-get install libpython3.6-dev

Solution 4

export LD_LIBRARY_PATH=[your python path to libpython3.4m.so]

libpython3.4m.so is under your python source from which you built it.

Put it in your .bashrc to set it at login automatically.

I can't force virtualenv to 3.4 on my machine but you can see that under lib of your virtualenv there's just a bunch of symlink to your local python installation. I guess libpython3.4m.so is fetch by one of those.

Solution 5

This one worked for me.

cd ~/
vim .bashrc
export LD_LIBRARY_PATH=~/miniconda/envs/python3.6/lib/
Share:
106,032
user785099
Author by

user785099

Updated on July 09, 2022

Comments

  • user785099
    user785099 almost 2 years

    I have created a python virtual environment using virtualenv, after activating it, I can see where is Python installed in my shell as following:

    (virtualenv-test) bash-4.1$ whereis python
    python: /usr/bin/python2.6 /usr/bin/python2.6-config /usr/bin/python
    /usr/lib/python2.6 /usr/lib64/python2.6 /usr/X11R6/bin/python2.6
    /usr/X11R6/bin/python2.6-config /usr/X11R6/bin/python
    /usr/bin/X11/python2.6 /usr/bin/X11/python2.6-config
    /usr/bin/X11/python /usr/include/python2.6
    /usr/share/man/man1/python.1.gz
    

    Also I can see what python version I'm using:

    (virtualenv-test) bash-4.1$ which python
    /data/virtualenv-test/bin/python
    

    However, after typing python, I got the following error message:

    (virtualenv-test) bash-4.1$ python
    python: error while loading shared libraries: libpython3.4m.so.1.0: cannot open shared object file: No such file or directory
    

    What can be the underlying reason?