Search code examples
pythonlinuxpython-3.xvlclibvlc

Can I use libVLC's Python bindings with Python 3.x?


I want to use libVLC to build a video scheduler for Linux. The PythonBinding wiki for libVLC states that it can be used with Python version greater than 2.5. However, I couldn't find any information explicitly stating that it does or does not work with Python 3.x.


Solution

  • The code you're linking includes a compatibility layer that checks the python version and sets up some variables in order to make the code work in both Python 2 in Python 3:

    if sys.version_info[0] > 2:
        str = str
        unicode = str
        bytes = bytes
        basestring = (str, bytes)
        PYTHON3 = True
        ...
    else:
        str = str
        unicode = unicode
        bytes = str
        basestring = basestring
        PYTHON3 = False
        ...
    

    This looks like a good hint that Python 2 and 3 are meant to be supported at the same time.

    (Note that many libraries use a standard helper library called six to keep the code polyglotic, instead of doing this manually like vlc.py, but I understand the authors of this library wanted to avoid external dependencies.)