1

我在尝试制作我的第一个 spotify 应用程序时遇到了问题。我在树莓派上,运行 Arch。

我在一个目录中有我的__main__.py和我spotify_appkey.key的,我运行它[root@RPI]# python2 __main__.py

中的代码__main__.py如下所示:

import spotify
print "1"
session = spotify.Session()
print "2"
try:
    session.login('myUsername', 'myPassword')
    print "3"
except IOError as e:
    print "error({0}): {1}".format(e.errno, e.strerror)

这给了我这个输出:

1
2
Segmentation fault (core dumped)

阅读此链接,我也尝试过:

import spotify
print "1"
session = spotify.Session()
print "2"
config = spotify.Config()
print "3"
try:
    session.login('myUsername', 'myPassword')
    print "4"
except IOError as e:
    print "error({0}): {1}".format(e.errno, e.strerror)

这给了我这个:

1
2
Traceback ..... yada yada ...
    File "__main__.py" ... yada yada...
        config = spotify.Config()
AttributeError: 'module' object has no attribute 'Config'

我究竟做错了什么?

4

1 回答 1

2

pyspotify 的作者在这里 :-)

dano 是对的:您似乎正在阅读 v2.x 文档并使用 v1.x。v2.x 是完全重写的,使用不同的并且希望使用更简单的 API,因此您必须使用与您编码的版本相匹配的文档:

在这一点上,我建议对所有新应用程序使用 v2.x。v2.x API 更易于使用,适用于更多 Python 版本,涵盖完整的 libspotify API,并且得到积极维护。第一个测试版 v2.0.0b1 于昨天发布。最终的 v2.0.0 版本有望在几周后发布。

如果你想立即在 Arch 上运行 pyspotify v2.x,你可以使用 yaourt 安装 libspotify:

sudo yaourt -S libspotify

使用 pacman 安装 pyspotify 构建依赖项:

sudo pacman -S base-devel

然后使用 pip 安装最新的 pyspotify beta 版本(在 virtualenv 中或使用 sudo):

pip install --pre pyspotify

--pre在pyspotify 2.0.0 final 发布之前,该标志是必需的。

有关更多详细信息,请参阅http://pyspotify.mopidy.com/en/latest/installation/

pyspotify v2.x 可能会在最终发布后不久出现在 AUR 中。

于 2014-04-25T08:13:36.030 回答