31

I have two versions Python-2.7 , Python-3.5 which I was able to access with python(pip) and python3(pip3) command respectively. Then I have installed an another version of python (i.e 3.7.5).

I have used these commands to install it.

sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
xz-utils tk-dev libffi-dev liblzma-dev

wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz
tar xvf Python-3.7.5.tgz
cd Python-3.7.5
./configure --enable-optimizations --enable-shared
make -j6
sudo make altinstall

Everything was successful but the only issue is I was not able to access Python-3.7 using the command python3.7.

When I used python3.7 it returned this following error:

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

Can anyone please help me regarding how to fix this issue?

Info: OS: Debian GNU/Linux 9.11 (stretch)

Output when I type:

user_83@debian-241:~$ whereis python     
python: /usr/bin/python3.5m-config 
/usr/bin/python3.5m 
/usr/bin/python2.7-config 
/usr/bin/python3.5 
/usr/bin/python2.7 
/usr/bin/python 
/usr/bin/python3.5-config 
/usr/lib/python3.5 
/usr/lib/python2.7 
/etc/python3.5 
/etc/python2.7 
/etc/python 
/usr/local/bin/python3.7m 
/usr/local/bin/python3.7 
/usr/local/bin/python3.7m-config 
/usr/local/lib/python3.5 
/usr/local/lib/python2.7 
/usr/local/lib/python3.7
/usr/include/python3.5m 
/usr/include/python3.5 
/usr/include/python2.7 
/usr/share/python 
/usr/share/man/man1/python.1.gz

UPDATE:

locate libpython3.5m

/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu/libpython3.5m-pic.a
/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu/libpython3.5m.a
/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu/libpython3.5m.so
/usr/lib/x86_64-linux-gnu/libpython3.5m.a
/usr/lib/x86_64-linux-gnu/libpython3.5m.so
/usr/lib/x86_64-linux-gnu/libpython3.5m.so.1
/usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0

locate libpython3.7m
/usr/local/lib/libpython3.7m.so
/usr/local/lib/libpython3.7m.so.1.0
/usr/local/lib/python3.7/config-3.7m-x86_64-linux-gnu/libpython3.7m.a


sudo ldconfig /usr/local/lib 

ldconfig: /usr/lib/libnvinfer.so.5 is not a symbolic link
ldconfig: /usr/lib/libnvonnxparser_runtime.so.0 is not a symbolic link
ldconfig: /usr/lib/libnvonnxparser.so.0 is not a symbolic link
ldconfig: /usr/lib/libnvparsers.so.5 is not a symbolic link
ldconfig: /usr/lib/libnvinfer_plugin.so.5 is not a symbolic link
user_12
  • 1,778
  • 7
  • 31
  • 72
  • did you check if apt on Debian doesn't have precompiled Python3.7 ? On Linux Mint I use `apt` to install precompiled Python 3.7 from unofficial repo for Ubuntu - maybe it can works also for Debian - https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa – furas Oct 31 '19 at 18:46
  • 1
    using `find` or `locate` you can try to find `libpython3.7m.so.1.0` and compare its path with full path to `libpython3.5` - maybe you have to manually move it to correct folder. – furas Oct 31 '19 at 18:49
  • I tried to update python using `sudo apt install python2` but it returned python 3.5 as the latest version available. So that's why I installed it via above method. – user_12 Oct 31 '19 at 18:51
  • @furas can you provide the commands on how to do that. I'm new to linux os. I really have no idea on how to do it. – user_12 Oct 31 '19 at 18:52
  • I'm not sure if `locate` is always installed. It creates database with all filename - `sudo updatedb` - and later you can search - `locate libpython3.7m.so.1.0`. Because it uses database so it search very fast but from time to time you have to use `updatedb` to update data in this database. – furas Oct 31 '19 at 18:56
  • normally should be installed `find`. It search directly in folders - `sudo find / -name libpython3.7` - so it check current content on disk but it may run much slower. – furas Oct 31 '19 at 18:59
  • 1
    @furas As you mentioned I tried using `locate libpython3.7m.so.1.0` and it returned `/usr/local/lib/libpython3.7m.so.1.0` – user_12 Oct 31 '19 at 19:04
  • and what did you get for `libpython3.5m` ? Is it in the same folder ? If not then try to copy `libpython3.7m.so.1.0` to folder where you have `libpython3.5m` – furas Oct 31 '19 at 19:08
  • @furas can you check the question I updated what I've got for searching `locate libpython3.5m`. It returned multiple locations. Can you tell me what command I should use to copy everything correctly. – user_12 Oct 31 '19 at 19:11
  • I have `/usr/lib/x86_64-linux-gnu/libpython3.7m.so.1.0` and `/usr/lib/python3.7/config-3.7m-x86_64-linux-gnu/libpython3.7m.so` similar to folders with `libpython3.5m`. The same with other files: `libpython3.7m.so.1`, `libpython3.7m.so` and `libpython3.7m.a` – furas Oct 31 '19 at 19:13
  • I'm not sure if Debian uses `Python3` to run something in system but maybe you should use `make install` instead of `make altinstall` – furas Oct 31 '19 at 19:16
  • yes even I wasn't sure so I used `make altinstall`. So is there a way to remove everything so I can again install it with `make install`. I don't know the commands to remove. – user_12 Oct 31 '19 at 19:18
  • 1
    For Python `install` runs `altinstall` and few other commands so you don't have to remove it. [Difference in details between “make install” and “make altinstall”](https://stackoverflow.com/questions/16018463/difference-in-details-between-make-install-and-make-altinstall) – furas Oct 31 '19 at 19:49
  • i have this error "Python3.7: error while loading shared libraries: libpython3.7m.so.1.0" on apline linux. What can i do ? – Gabriel Wu May 16 '22 at 12:27
  • For me this error occurs within "pipenv shell" – Eric Burel Nov 21 '22 at 10:21

4 Answers4

48

You need to add /usr/local/lib/ to the library search path. You can call the following in the current shell before running python3.7:

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

Or run ldconfig to add the path to the linker cache:

sudo ldconfig /usr/local/lib 
MEE
  • 2,114
  • 17
  • 21
  • 1
    it worked when I used `export LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib` but do I need to use this command everytime before using python3.7? – user_12 Oct 31 '19 at 19:29
  • when I used `sudo ldconfig /usr/local/lib` it returned some output. I've posted it in the question above. I think it's a error saying it's not a symbolic link or something. – user_12 Oct 31 '19 at 19:32
  • Nothing to worry about in that output. – MEE Oct 31 '19 at 19:33
  • So it it done now? I mean will it work always even after reboot? – user_12 Oct 31 '19 at 19:33
  • Yes, it should work after rebooting if you made the changes permanent as explained above. If you only used `export` in the current shell it will only impact the current shell session. – MEE Oct 31 '19 at 19:36
  • I haven't make changes permanent. Can you please also include those steps in the answer above. I really don't know how to do it? – user_12 Oct 31 '19 at 19:37
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/201679/discussion-between-john-and-user-12). – MEE Oct 31 '19 at 19:37
  • 1
    `sudo ldconfig` did it for me – Juancki Oct 29 '20 at 14:44
  • None of these worked for me. No error messages or console output. – Ben Alan Sep 19 '22 at 21:24
18

I just installed the required library using:

sudo apt-get install libpython3.7
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
4

I'm using homebrew/linuxbrew to manage my latest python3 version. Doing this export LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib:/home/linuxbrew/.linuxbrew/Cellar/python@3.8/3.8.3/lib works for me (no reboot need).

nsphung
  • 173
  • 1
  • 1
  • 9
  • Thanks, also came up with this - since docker-compose version 1.25.5 it was broken for me in a Ubuntu 18.04.4 environment using linuxbrew inside WSL with message: /home/linuxbrew/.linuxbrew/Cellar/docker-compose/1.25.5_2/libexec/bin/python3.8: error while loading shared libraries: libpython3.8.so.1.0: cannot open shared object file: No such file or directory – Philipp Jun 03 '20 at 11:09
1

pip3 install uwsgi worked for me

Bruce Leat
  • 19
  • 1