我正在尝试使用 python 为一个小项目制作一个纯音频播放器。我使用的脚本如下:
#!/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
现在,这个脚本在我运行 manjaro 和以下 python 版本的工作机器上运行良好:
Python 3.7.2 (default, Jan 10 2019, 23:51:51)
我计划运行这个脚本的机器是一个运行 raspbian 拉伸的树莓派零 W,我将它设置为运行这个 python 版本:
Python 3.5.3 (default, Sep 27 2018, 17:25:39)
当我在树莓派上运行这个脚本时,我什么也得不到,当我停止它时,我收到以下消息:
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
一一运行命令,我想我发现了vlc module
. 当脚本到达以下命令时:
player=vlc.MediaPlayer(playurl)
我得到:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'vlc' has no attribute 'MediaPlayer'
作为参考,我使用 pip3 安装了 python-vlc、pafy 和 youtube_dl 模块。
这是我第一次接触 Python。通过阅读这里和其他网站上的几篇文章,我已经走到了这一步。这完全让我感到困惑,我不知道该怎么做才能让它工作。
完全有可能在 raspbian 上安装 python 存在问题(我使用的是全新安装,只是昨晚我重新安装了它!)。我添加到全新 raspbian 安装中的唯一内容是更新系统、安装 git 和其他一些程序。
有人可以帮我吗?