Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ubuntu 20.04 upgrade, Python missing libffi.so.6

I recently upgraded my OS to Ubuntu 20.04 LTS.

Now when I try to import a library like Numpy in Python, I get the following error:

ImportError: libffi.so.6: cannot open shared object file: No such file or directory

I tried installing the libffi package, but apt can't locate it :

sudo apt-get install libffi
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package libffi
like image 839
Kh4zit Avatar asked May 18 '20 17:05

Kh4zit


4 Answers

If you are using pyenv, you should just uninstall the used python version and then reinstall it.

Example:

pyenv uninstall 3.7.4
pyenv install 3.7.4

It's cleaner and safer than renaming system library from my point of view.

like image 69
amichaud Avatar answered Nov 18 '22 15:11

amichaud


It seems like I fixed it. I could be wrong, but here is what I think happened:

  1. Ubuntu 20.04 upgraded libffi6 to libffi7
  2. Python is still looking for libffi6

What I did to fix it :

Locate libffi.so.7 in your system

$ find /usr/lib -name "libffi.so*"

Create a simlink named libffi.so.6 that points to libffi.so.7:

sudo ln -s /usr/path/to/libffi.so.7 /usr/lib/path/to/libffi.so.6

UPDATE:

As noted by many users, this fix could have unintended consequences. The better way to do it is to reinstall python as @amichaud explained. This should be used as a last resort IF you're not using pyenv/virtualenv/etc in which case removing python will cause a lot of dependencies to be removed as well.

like image 34
Kh4zit Avatar answered Nov 18 '22 16:11

Kh4zit


I am using Xubuntu 20.04 and recompiling the python version 3.7 did not work for me.

The way I solved this was to download the 19.10 version of the package from here: http://mirrors.kernel.org/ubuntu/pool/main/libf/libffi/libffi6_3.2.1-8_amd64.deb

and then installing it

sudo apt install ./libffi6_3.2.1-8_amd64.deb

This will unpack the libffi.so.6 and libffi.so.6.0.4 files to /usr/lib/x86_64-linux-gnu/. The libffi.so.6 file is just a link to libffi.so.6.0.4 in the same directory.

As far as I could see this does not overwrite any files so should be safe.

like image 68
antisa Avatar answered Nov 18 '22 16:11

antisa


Ubuntu 20 has libffi7 installed instead. It's possible to install the previous version using coming from Ubuntu 19.10 (Eoan Ermine) download from here Or you can follow these commands

$ curl -LO http://archive.ubuntu.com/ubuntu/pool/main/libf/libffi/libffi6_3.2.1-8_amd64.deb

$ sudo dpkg -i libffi6_3.2.1-8_amd64.deb
like image 19
sushmita wable Avatar answered Nov 18 '22 14:11

sushmita wable