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

PythonPython 3.xVirtualenv

Python Problem Overview


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?

Python Solutions


Solution 1 - Python

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 - Python

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 - Python

For Python 3.6, it was fixed by

sudo apt-get install libpython3.6-dev

Solution 4 - Python

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 fetched by one of those.

Solution 5 - Python

For me, libpython3.6m.so.1.0 was in the folder where I downloaded Python source (~/Python3.6.9).

I simply did:

sudo cp ~/Python3.6.9/libpython3.6m.so.1.0 /usr/local/lib/python3.6/

and:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/python3.6

Solution 6 - Python

This one worked for me.

cd ~/
vim .bashrc
export LD_LIBRARY_PATH=~/miniconda/envs/python3.6/lib/

Solution 7 - Python

Kudos to above, For python 3.X you can fix this issue with:

sudo apt-get install libpython3.x-dev

No need to any changes to environment path manually.

Solution 8 - Python

I got it running by installing the package:

sudo apt-get install libpython3.x-dev

Solution 9 - Python

On python 3.8, I resolved this by deleting the virtualenv directory (./venv in my case) and recreating using python's built-in venv module installed of the pip-installed virtualenv. I'm on arch linux and also first did sudo pacman -Syu. Python was originally installed using just sudo pacman -S python.

$ rm -r ./venv
$ python -m venv venv
$ . ./venv/bin/activate
$ python --version
Python 3.8.1

Solution 10 - Python

If you are manually installing another python3 or python,

e.g: python3.6,

the active files(e.g: python3.6, python3.6m, python3.6m-config) are located at /usr/local/bin,

the library files(e.g: python3.6, libpython3.so, libpython3.6m.so.1.0) are located at /usr/local/lib,

While you do not configure any environment before make & make install,

Now you need to add the load_library_path(LD_LIBRARY_PATH) of python3.6,

if you are using zsh, just:

cd ~

vim ~/.zshrc

Add the below code to ~/.zshrc:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/

Just use :wq to save and quit the configuration file of zsh,

also, you need to active the hnewable .zshrc:

source ~/.zshrc

then try:

python

If you use bash, just:

cd ~

vim ~/.bashrc

And the below code to ~/.bashrc:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/

Just use :wq to save and quit the configuration file of bash,

also, you need to active the newable .bashrc:

source ~/.bashrc

Now, for your turn!

First, you need to found out where libpython3.4m.so.1.0 is?

From you asked and told, I guess libpython3.4m.so.1.0 is located at

/data/virtualenv-test/lib/ because I saw your python is located at

/data/virtualenv-test/bin/python.

Second, add that loading library path to your bash's configuration file ~/.bashrc:

cd ~

vim ~/.bashrc

Use i to enter VIM editing state, and add the below code to ~/.bashrc:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/data/virtualenv-test/lib/

Use :wq to save and quit .bashrc, and active the newable .bashrc:

source ~/.bashrc

Third, test your installed Python.

All in all, you could change the upsatirs /data/virtualenv-test/lib/ to

yours(where libpython3.4m.so.1.0 is).

END!

Solution 11 - Python

I could solve it by installing libpython3.X without the (-dev). In your case, it gives:

sudo apt-get install libpython3.4

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser785099View Question on Stackoverflow
Solution 1 - PythonwilliezhView Answer on Stackoverflow
Solution 2 - PythonbuxizhizhoumView Answer on Stackoverflow
Solution 3 - PythonA. AttiaView Answer on Stackoverflow
Solution 4 - PythonPobeView Answer on Stackoverflow
Solution 5 - PythonAstariulView Answer on Stackoverflow
Solution 6 - PythonAjay-2007View Answer on Stackoverflow
Solution 7 - PythonSinaView Answer on Stackoverflow
Solution 8 - PythonharbingerView Answer on Stackoverflow
Solution 9 - PythonJakeView Answer on Stackoverflow
Solution 10 - PythonVittore MarcasView Answer on Stackoverflow
Solution 11 - PythonvinzeeView Answer on Stackoverflow