I am trying to make an audio-only player using python for a small project. The script I am using is as follows:
#!/usr/bin/env python
import re
import sys
import pafy
import vlc
url = "https://www.youtube.com/watch?v=G0OqIkgZqlA"
video = pafy.new(url)
best = video.getbestaudio()
playurl = best.url
player = vlc.MediaPlayer(playurl)
player.play()
while True: pass
Now, this script works great on my work machine running manjaro and the following python version:
Python 3.7.2 (default, Jan 10 2019, 23:51:51)
The machine I plan to run this script is a raspberry pi zero W running raspbian stretch and I set it to run this python version:
Python 3.5.3 (default, Sep 27 2018, 17:25:39)
When I run this script on the raspberry pi I get nothing and when I stop it I get the following messages:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/youtube_dl/extractor/__init__.py", line 4, in <module>
from .lazy_extractors import *
ImportError: No module named 'youtube_dl.extractor.lazy_extractors'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "box.py", line 4, in <module>
import pafy
File "/usr/local/lib/python3.5/dist-packages/pafy/__init__.py", line 7, in <module>
from .pafy import new
File "/usr/local/lib/python3.5/dist-packages/pafy/pafy.py", line 48, in <module>
import youtube_dl
File "/usr/local/lib/python3.5/dist-packages/youtube_dl/__init__.py", line 43, in <module>
from .extractor import gen_extractors, list_extractors
File "/usr/local/lib/python3.5/dist-packages/youtube_dl/extractor/__init__.py", line 9, in <module>
from .extractors import *
File "/usr/local/lib/python3.5/dist-packages/youtube_dl/extractor/extractors.py", line 732, in <module>
from .newgrounds import (
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 954, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 896, in _find_spec
File "<frozen importlib._bootstrap_external>", line 1147, in find_spec
File "<frozen importlib._bootstrap_external>", line 1121, in _get_spec
File "<frozen importlib._bootstrap_external>", line 1229, in find_spec
File "<frozen importlib._bootstrap_external>", line 82, in _path_stat
KeyboardInterrupt
Running the commands one by one, I think I found the problem with the vlc module
. When the script reaches the following command:
player=vlc.MediaPlayer(playurl)
I get:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'vlc' has no attribute 'MediaPlayer'
For reference I used pip3 to install python-vlc, pafy and youtube_dl modules.
This is my first ever experience with Python. I got this far by reading from several posts on here and other sites. This completely confuses me and I have no idea what to do to make it work.
It is entirely possible that there is a problem with the python installation on raspbian (I am using a completely fresh install, only last night I reinstalled it again!). The only thing I added to the fresh raspbian install was to update the system, install git and a few other programs.
Can someone please help me out?
The problem seems to be related to two versions of vlc package (32 bit vs 64bit). There are two ways to install it as well: python-vlc vs vlc. Please check which system version you have and install the correct package version for it. You may still experience the same problem I had where I was missing some DLLs.
I hope the following links will help:
Error when importingPython-vlc
pip install vlc
does not have the MediaPlayer classpip install python-vlc
has the MediaPlayer class but gives a DLL lib error