Python-VLC Bindings
Python-VLC provides Python bindings for the VLC media player. It allows developers to integrate VLC's powerful multimedia capabilities, such as playing audio and video, streaming, and capturing, directly into Python applications. The current version, 3.0.21203, is generally kept in sync with major VLC releases, reflecting VLC 3.x features. While releases aren't on a strict cadence, updates typically follow significant VLC player developments.
Common errors
-
OSError: [Errno 0] Error loading libvlc.dll
cause The VLC media player is either not installed or its dynamic link libraries (libvlc.dll/libvlccore.dll) cannot be found by python-vlc. This often happens on Windows if VLC's installation directory is not in the system PATH.fixInstall VLC media player from its official website. If already installed, add the VLC installation directory (e.g., `C:\Program Files\VideoLAN\VLC`) to your system's PATH environment variable and restart your terminal/IDE. -
OSError: libvlc.so.X not found
cause Similar to the Windows error, this indicates that the VLC shared libraries (`libvlc.so`, `libvlccore.so`) are not found on Linux systems. This usually means VLC is not installed or not in standard library paths.fixInstall VLC media player using your distribution's package manager (e.g., `sudo apt install vlc` on Debian/Ubuntu, `sudo dnf install vlc` on Fedora). Ensure `libvlc-dev` or similar development packages are also installed if required for bindings. -
NameError: name 'vlc' is not defined
cause The 'vlc' module has not been imported before being used.fixAdd `import vlc` at the beginning of your Python script or interactive session.
Warnings
- gotcha python-vlc are bindings, not the player itself. You *must* have VLC media player installed on your system for python-vlc to function. This is often overlooked.
- gotcha VLC library discovery can be platform-specific. On Windows, ensure VLC's installation directory (e.g., `C:\Program Files\VideoLAN\VLC`) is added to your system's PATH environment variable. On Linux/macOS, ensure VLC is installed via a package manager so its shared libraries (`libvlc.so`/`.dylib`) are in standard locations.
- breaking Compatibility issues may arise if your system's installed VLC media player version is significantly older or newer than what the python-vlc bindings expect (typically VLC 3.x for current python-vlc versions).
Install
-
pip install python-vlc
Imports
- vlc
import vlc
Quickstart
import vlc
import time
import os
# NOTE: You MUST have VLC media player installed on your system.
# For Windows: ensure VLC is installed and its directory (e.g., C:\Program Files\VideoLAN\VLC) is in your PATH.
# For Linux/macOS: VLC libraries are usually found automatically if installed via package manager.
# Create a VLC instance
instance = vlc.Instance(['--no-xlib'])
# Create a media player
player = instance.media_player_new()
# Path to a dummy video file for demonstration.
# Replace 'path/to/your/video.mp4' with an actual video file on your system.
# For testing, you can download a sample video or create a dummy file.
# Example: 'file:///home/user/Videos/test.mp4' or 'C:\Users\User\Videos\test.mp4'
media_file = os.environ.get('VLC_TEST_MEDIA_PATH', 'file:///path/to/your/video.mp4')
# Create a media object from the file
media = instance.media_new(media_file)
# Set the media to the player
player.set_media(media)
# Play the media
print(f"Attempting to play: {media_file}")
player.play()
# Wait for a few seconds to allow playback (adjust as needed)
time.sleep(5)
# Stop the player
player.stop()
print("Playback stopped.")