'python: error while loading shared libraries: libpython3.4m.so.1.0: cannot open shared object file: No such file or directory
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?
Solution 1:[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
orinclude /usr/local/lib
) - Then, activate the new configuration by running
sudo /sbin/ldconfig -v
.
Solution 2:[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:[3]
For Python 3.6, it was fixed by
sudo apt-get install libpython3.6-dev
Solution 4:[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 fetched by one of those.
Solution 5:[5]
This one worked for me.
cd ~/
vim .bashrc
export LD_LIBRARY_PATH=~/miniconda/envs/python3.6/lib/
Solution 6:[6]
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 7:[7]
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:[8]
I got it running by installing the package:
sudo apt-get install libpython3.x-dev
Solution 9:[9]
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:[10]
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:[11]
I could solve it by installing libpython3.X
without the (-dev
). In your case, it gives:
sudo apt-get install libpython3.4
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow