python-mpv
python-mpv copied to clipboard
missing libmpv on Raspberry Pi
I am trying to run the simple first script to just play a video file. The script fails
pi@raspberrypi:~ $ python3 m.py Traceback (most recent call last): File "m.py", line 1, in <module> import mpv File "/usr/local/lib/python3.7/dist-packages/mpv.py", line 49, in <module> raise OSError("Cannot find libmpv in the usual places. Depending on your distro, you may try installing an " OSError: Cannot find libmpv in the usual places. Depending on your distro, you may try installing an mpv-devel or mpv-libs package. If you have libmpv around but this script can't find it, consult the documentation for ctypes.util.find_library which this script uses to look up the library filename. pi@raspberrypi:~ $
There is no libmpv on my system and it is up to date. What do I do to resolve this. This is Rasbian Buster.
Have you installed the library? The shared library is in libmpv1 IIRC.
"RuntimeError: python-mpv requires libmpv with an API version of 1.108 or higher (libmpv >= 0.33), but you have an older version (1.107)."
ii libmpv1:armhf 0.32.0-3 armhf video player based on MPlayer/mplayer2 (client library)
ii mpv 0.32.0-3 armhf video player based on MPlayer/mplayer2
Currently available libmpv1 does not work with python-mpv on Raspberry Pi bullseye (debian 11).
Debian is a bit difficult, because they insist on using obsolete versions of software. libmpv 0.32.0, which is the current version in debian 11, is from January 2020, over three years ago now. What you can do to work around this without installing a more recent libmpv is to pin python-mpv to an old version using e.g. pip install python-mpv<=some_version
. Version 0.5.2 from July 2020 should be a good bet. There is a list of all historical versions before 2023 at the old pypi project page at https://pypi.org/project/python-mpv/#history
Thanks, that was also my idea. I will try that path you pointed out.
But is your software really needing/relying on the "new" features of the newer libmpvs? I did not dig into the source, just wanted to ask you - this would allows users of Raspberry Pis to use it - just in case.
FYI python3-mpv is already packaged for Debian.
But not for Raspbian (subject of this issue).
sudo apt install python-mpv
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package python-mpv
cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 11 (bullseye)"
NAME="Raspbian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
Info for @jaseg : 0.5.2 works!
Small test program playing an internet radio (SomaFM Groove Salad) and showing timestamp and music title on change.
# sudo apt install mpv libmpv-dev python3-mpv
import mpv
import signal
from datetime import datetime
def now():
currentDateAndTime = datetime.now()
return currentDateAndTime.strftime("%Y%m%d%H%M%S")
def make_observer(player_name):
def observer(_prop_name, prop_val):
# print(f'{player_name}: {prop_val}')
try:
title = prop_val['icy-title']
print( now() + " " + title )
except:
pass
return observer
# Play SomaFm Groove Salad
player = mpv.MPV()
player.ao="alsa"
player.volumemax="600.0" # to get same volume as with mplayer
player.volume=30.0 # set a low start volume
player.play('http://ice1.somafm.com/groovesalad-128-mp3')
player.observe_property('metadata', make_observer('player'))
signal.pause()
E: Unable to locate package python-mpv
Python 2 support was dropped by upstream (here) a while ago, also the package I mentioned was python3-mpv. Bullseye still have python
aliases to Python 2 for historical reasons.
Yes, of course, it's (almost) the same: 0.5.2-1. I overlooked that issue.... thanks!
But is your software really needing/relying on the "new" features of the newer libmpvs? I did not dig into the source, just wanted to ask you - this would allows users of Raspberry Pis to use it - just in case.
libmpv changes quite rapidly, and the last few years brought some very cool new API such as the new rendering API, the updated OpenGL API. I would recommend simply keeping libmpv up to date.
In case you can't or don't want to move away from debian stable's libmpv build, I actually think using an older python-mpv version is completely fine. Since python-mpv is only a thin wrapper around libmpv, you're not missing out on much when sticking with an older version, except for new goodies introduced in later libmpvs.
It is working fine now! Thank you. Moved from mplayer
(mostly defunct when you wish to rely on it...) to your lib just today.
https://github.com/Wikinaut/pinetradio