Snap including a pip package

Hi there

I am having problems packaging a software written in python that need a specific pip package, which does not have a deb package to install. So, the pip package in question is “python-vlc”. There is no deb package for the version I am packaging against (18.04) and all possible solutions I know does not work. I tried to include this dependency on setup.py as install_requires, on requirements.txt…

How can I make snapcraft prime/stage this python module?

Thanks for your attention.

The python plugin can handle these arguments passed to the snapcraft part (retrieved by running snapcraft help python under your current project):

    - requirements:
      (list of strings)
      List of paths to requirements files.
    - constraints:
      (list of strings)
      List of paths to constraint files.
    - process-dependency-links:
      (bool; default: false)
      Enable the processing of dependency links in pip, which allow one
      project to provide places to look for another project
    - python-packages:
      (list)
      A list of dependencies to get from PyPI
    - python-version:
      (string; default: python3)
      The python version to use. Valid options are: python2 and python3

Yes, I know that instructions. I tried that.

parts:
  opendvdproducer:
    plugin: python
    python-packages:
      - PyQt5
      - python-vlc
    stage-packages:
      - python3-pyqt5
      - ffmpeg
      - dvdauthor
      - imagemagick
      - genisoimage
      - vlc
    after:
      - desktop-qt5

still getting:

Traceback (most recent call last):
  File "/snap/opendvdproducer/36/share/opendvdproducer/opendvdproducer.py", line 4, in <module>
    import os, sys, subprocess, time, random, codecs, tempfile, shutil, copy, vlc
ModuleNotFoundError: No module named 'vlc'

I quickly created this video with a small project that uses python-vlc, I did not get to satisfying the dependencies on ctypes that that module has, but at least I hope this proves that the module should just be found,
asciicast

1 Like

Thanks a lot, @sergiusens!

I have found the source of my problem: At the beginning of the script (both setup.py and the opendvdproducer.py itself) it was referring to #!/usr/bin/python3, but I changed to #!/usr/bin/env python3. Now all works as expected.

Again, thanks for your attention and help investigating this issue.

2 Likes

Sorry resurrecting this post. But I was reading about linking other snaps into my snap. Would it be possible to make a snap “depend” on the vlc snap and make use of its libraries? So my snap would not need to package all libs and plugins as they are already on the vlc snap?

If there is to snap adding a slot for the content interface, at the end of the day, no matter the mechanism you will have to add it in. The reason for one not being available is probably the fact that one would need to commit to ABI and API stability at runtime to never break a user and that is not an easy task.