Trouble getting a PIP Package to work as a snap

The problem comes down to Python’s ctypes.util find_library() having a dependency on /sbin/ldconfig, when the host has liblept installed, the snap works, if the host doesn’t, the snap fails. Even if the host has a copy of the library, the snap would still be using it’s own version bundled internally.

The easiest fix would be to change the one line that even bothers looking for the library, because this is in a snap, we know the library will always where we put it. Keep the $LD_LIBRARY_PATH change, and under ocrmypdfgui part, add the following.

override-build: |
      snapcraftctl build
      sed -i 's/find_library(libname)/"liblept.so.5"/g' $SNAPCRAFT_PART_INSTALL/lib/python3.6/site-packages/ocrmypdf/leptonica.py

It’s also worth mentioning you should probably change,

desktop: /build/ocrmypdfgui/parts/get-source/src/gui/ocrmypdfgui.desktop

to

desktop: $SNAPCRAFT_PROJECT_DIR/gui/ocrmypdfgui.desktop

So that it builds correctly regardless of absolute paths which aren’t guaranteed to be consistent. You can then drop the following part entirely, since I presume it’s only there to have gotten the .desktop file somewhere you expected it.

parts:
  get-source:
    plugin: dump
    source: https://github.com/alexanderlanganke/ocrmypdfgui.git

Here’s a link to the line in the Python VM source that’s the root of the issue, for the curious.

1 Like