Ubuntu 20.04 upgrade, Python missing libffi.so.6

51,140

Solution 1

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.

Solution 2

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.

Solution 3

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.

Solution 4

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

Solution 5

Same problem for me

  1. Upgraded to ubuntu 20
  2. pip didn't work anymore (same error)

What I did was:

  1. deleted the virtual env I was using
  2. recreated it
  3. Sure, I wasn't able to do a pip freeze to get save my dependencies (as pip didn't work), but fortunately I didn't care about them.
Share:
51,140
Kh4zit
Author by

Kh4zit

Updated on October 21, 2021

Comments

  • Kh4zit
    Kh4zit about 1 year

    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
    
  • bsplosion
    bsplosion over 2 years
    This is the right way to do it - faking a lib version is a last-resort option and could have unintended consequences.
  • Grzegorz Bokota
    Grzegorz Bokota over 2 years
    even pyenv install 3.7.4 -f which allows to not recreate virtualenvs
  • Franey
    Franey over 2 years
    Reinstalling Python is the ticket, whether with pyenv or otherwise. Python will find the updated library when it's building.
  • David Waterworth
    David Waterworth over 2 years
    This really should be the top / accepted answer! symlinking a different lib seems like a recipe for disaster
  • David Waterworth
    David Waterworth over 2 years
    I'd be very surprised if this actually works - symlinking one version of a lib to a different version seems likely to cause instability. Rebuilding python seems to be the proper solution
  • David Waterworth
    David Waterworth over 2 years
    PS I had to actually remove and reinstall pyenv
  • Kh4zit
    Kh4zit over 2 years
    It actually worked for me. I'm aware that it's not the cleanest way to do it, but this way you can avoid reinstalling all the python packages / dependencies. Regarding the instability, I don't see why it's a "recipe for disaster". At worst, you'll just need to revert back to rebuilding python. That said, I'm willing to change the accepted answer if it can cause more concerning problems that I'm not aware of.
  • David Waterworth
    David Waterworth over 2 years
    When you say works though you appear to mean doesn't crash on startup. You cannot know if python is behaving slightly differently than it should because you're calling the wrong lib, subtle differences in execution could occur which would be impossible to detect. Easier but annoying would be a crash at some random point in the future because finally some python code results in a call to the lib which has changed enough that it fails in an obvious matter.
  • petobens
    petobens over 2 years
    This should definitely be the accepted answer as it works with (almost surely) no unintended consequences.
  • Robin De Schepper
    Robin De Schepper about 2 years
    If you want to avoid "losing" your installed packages just do pip freeze > backup.txt, remove the Python installs, reinstall them and use pip install -r backup.txt and you'll be back to your original state
  • nimgwfc
    nimgwfc about 2 years
    When I run pyenv uninstall 3.8.6 (my current python version) I get this error: pyenv: version `3.8.6' not installed
  • Phil Blackburn over 1 year
    I tried all the answers above, and they failed. This one worked on Ubuntu 21.04.
  • Madhuparna Bhowmik
    Madhuparna Bhowmik about 1 year
    This worked for me (Ubuntu 20.04).
  • David Bensoussan
    David Bensoussan about 1 year
    This also work for poetry users
  • hidefromkgb
    hidefromkgb 11 months
    Thanks! Confirmed to be working @ Ubuntu 20.04.2.