Skip to content

ModuleNotFoundError: No module named 'youtube_dl' #253

Open
@1marc1

Description

My issue is very similar to this issue.

I am running Mopidy as a service as the user mopidy. I have tried using both youtube_dl and yt-dlp. In both cases, when I want to play a track, I see the following in the logs:

Oct 31 22:44:09 rpi3.home.com mopidy[2279]: ERROR    [YouTubeCoreListener-11 (_actor_loop)] mopidy.listener Triggering event failed: tracklist_changed()
Oct 31 22:44:09 rpi3.home.com mopidy[2279]: Traceback (most recent call last):
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:   File "/usr/lib/python3/dist-packages/mopidy/listener.py", line 44, in on_event
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:     getattr(self, event)(**kwargs)
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:   File "/usr/local/lib/python3.11/dist-packages/mopidy_youtube/backend.py", line 61, in tracklist_changed
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:     [video.audio_url for video in videos]
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:   File "/usr/local/lib/python3.11/dist-packages/mopidy_youtube/backend.py", line 61, in <listcomp>
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:     [video.audio_url for video in videos]
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:      ^^^^^^^^^^^^^^^
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:   File "/usr/local/lib/python3.11/dist-packages/mopidy_youtube/youtube.py", line 38, in wrapper
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:     func(self)  # should create the future
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:     ^^^^^^^^^^
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:   File "/usr/local/lib/python3.11/dist-packages/mopidy_youtube/youtube.py", line 390, in audio_url
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:     youtube_dl = importlib.import_module(youtube_dl_package)
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:   File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:     return _bootstrap._gcd_import(name[level:], package, level)
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:   File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:   File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:   File "<frozen importlib._bootstrap>", line 1142, in _find_and_load_unlocked
Oct 31 22:44:09 rpi3.home.com mopidy[2279]: ModuleNotFoundError: No module named 'youtube_dl'
Oct 31 22:44:30 rpi3.home.com mopidy[2279]: ERROR    [YouTubeBackend-4 (_actor_loop)] mopidy_youtube translate_uri error "No module named 'youtube_dl'"
Oct 31 22:44:30 rpi3.home.com mopidy[2279]: WARNING  [Core-7 (_actor_loop)] mopidy.core.tracklist Track is not playable: youtube:video:3tmd-ClpJxA

When I uninstall youtube_dl and install yt-dlp, then the "missing" module is listed as yt_dlp.
Where my issue differs from the other issue is that when I run python and manually try to import the modules, I get a SyntaxError:

pi@rpi3:~ $ python 
Python 3.11.2 (main, May  2 2024, 11:59:08) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ytmusicapi
>>> import yt-dlp
  File "<stdin>", line 1
    import yt-dlp
             ^
SyntaxError: invalid syntax

The above also happens for when I run python as the root user or the mopidy user.

The commands I use to install youtube_dl and yt_dlp are:

$ sudo python3 -m pip install youtube_dl --break-system-packages
$ sudo python3 -m pip install yt-dlp --break-system-packages
$ yt-dlp --version
2024.10.22

The relevant section of my /etc/mopidy/mopidy.conf file is:

[youtube]
enabled = true
allow_cache = true
#youtube_api_key = ********
#api_enabled = true
musicapi_enabled = true
youtube_dl_package = yt-dlp

To simplify things, I disabled the API key initially when it wasn't working.

Any help is much appreciated.

Thank you.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions