2

After updating from Ubuntu 20.04 to Ubuntu 20.10 I am not able to run PyGObject applications on a Python Virtual Environment.

I can reproduce the issue following these simple steps:

sudo apt-get install python3-venv
python3 -m venv venv
source env/bin/activate
pip install PyGObject==3.38.0
python3 hw.py

Where hw.py is the standard PyGObject Hello World:

#!/usr/bin/env python3

import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk

window = Gtk.Window(title="Hello World")
window.show()
window.connect("destroy", Gtk.main_quit)
Gtk.main()

When I try to run it, it throws this error:

$ python3 hw.py 
Traceback (most recent call last):
  File "hw.py", line 3, in <module>
    import gi
  File "/home/leinardi/temp/hw/venv/lib/python3.8/site-packages/gi/__init__.py", line 40, in <module>
    from . import _gi
ImportError: libffi.so.7: cannot open shared object file: No such file or directory

Running hw.py on the System Environment works correctly (the issue only happens when using the Virtual Environment).

A workaround is to find and provide a copy of libffi.so.7 in /usr/lib/x86_64-linux-gnu/ but, since this library version is not available inside the official repositories of Ubuntu 20.10, this is a difficult and unsafe operation.

muru
  • 193,181
  • 53
  • 473
  • 722
Roberto Leinardi
  • 728
  • 10
  • 23

1 Answers1

6

I had a similar issue with libffi.so.6 but this was for 20.04, check my solution here https://stackoverflow.com/a/63329830/6881647

You can try the same thing on 20.10 by downloading the package from here https://mirrors.edge.kernel.org/ubuntu/pool/main/libf/libffi/libffi7_3.3-4_amd64.deb and installing it. This will put the 2 files (libffi.so.7 and libffi.so.7.1.0) inside of /usr/lib/x86_64-linux-gnu/ and it shouldn't overwrite anything.

Can you explain why you consider this to be difficult and unsafe? It's a simple deb install and as far as the unsafe part goes the package is provided by Ubuntu mirrors, not some third party or something.

antisa
  • 171
  • 2
  • Thanks! I had this same issue on Pop!_OS after upgrading to 20.10. I was unable to run one Python based utility, but installing the above deb fixed it for me. – Haprog Nov 08 '20 at 10:25
  • @antisa Yeah, an official Ubuntu mirror is OK, with "unsafe" I was referring about downloading some random zip or deb file from some 3rd party website. – Roberto Leinardi Nov 19 '20 at 23:47
  • After upgrading to Ubuntu 20.10, Jekyll stopped working for me with a similar error about libffi.so.7. Installing the libffi7 as explained in this answer helped me fix it. – curioustechizen Dec 18 '20 at 10:37
  • Download and install the .deb package works for me. I upgraded from Ubuntu 20.04 to 20.10 and I got this error. Thanks, @antisa – Fábio Filho May 03 '21 at 18:15