首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FluidSynth库的ImportError

FluidSynth库的ImportError
EN

Stack Overflow用户
提问于 2021-03-01 18:43:32
回答 1查看 352关注 0票数 0

这段代码的目的是使用QPushButton创建一个按钮,然后使用Pyfluidsynth库创建一个声音。我已经导入了time和pyfluidsynth,但我也尝试了导入fluidsynth (选项是存在的,但是我不知道有什么不同,它们都是随我安装的库一起提供的)。代码如下:

代码语言:javascript
复制
import sys
import time
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot
import pyfluidsynth

class App(QWidget):

    def __init__(self):
        super().__init__()
        self.title = 'PyQt5 button - pythonspot.com'
        self.left = 10
        self.top = 10
        self.width = 320
        self.height = 200
        self.initUI()

    def initUI(self):
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)

        button = QPushButton('PyQt5 button', self)
        button.setToolTip('This is an example button')
        button.move(100, 70)
        button.clicked.connect(self.PlayNote)

        self.show()

    def PlayNote(self):
        fs = pyfluidsynth.Synth()
        fs.start()

        sfid = fs.sfload("acoustic_grand_piano_ydp_20080910.sf2")
        fs.program_select(0, sfid, 0, 0)

        fs.noteon(0, 60, 30)
        time.sleep(1.0)

        fs.delete()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = App()
    sys.exit(app.exec_())

然而,当运行时,结果是一个ImportError:

代码语言:javascript
复制
Traceback (most recent call last):
  File "/Volumes/T7/MIDI Project/MIDI calculation.py", line 6, in <module>
    import pyfluidsynth
  File "/Users/ricochetnkweso/Library/Python/3.7/lib/python/site-packages/pyfluidsynth.py", line 43, in <module>
    raise ImportError("Couldn't find the FluidSynth library.")
ImportError: Couldn't find the FluidSynth library.
EN

回答 1

Stack Overflow用户

发布于 2021-03-02 00:36:18

看起来你需要安装FluidSynth的共享库。这是因为Pyfluidsynth只绑定到FluidSynth的API。

因此,需要在运行Pyfluidsynth的机器上安装一个版本的FluidSynth。共享库是一个文件,其中包含其他程序可以使用的编译代码。

您可以使用下面的链接获取适用于您的机器的Fluidsynth发行包。

https://github.com/nwhitehead/pyfluidsynth#requirements

代码语言:javascript
复制
REQUIREMENTS

FluidSynth 2.0.0 (or later version) (earlier versions are not supported. While they probably work, some features will be unavailble) http://www.fluidsynth.org/

    Windows/Android Binaries: https://github.com/FluidSynth/fluidsynth/releases
    MacOS/Linux Distributions: https://github.com/FluidSynth/fluidsynth/wiki/Download#distributions
    Building from Source: https://github.com/FluidSynth/fluidsynth/wiki/BuildingWithCMake

其他安装/编译信息位于:

https://github.com/FluidSynth/fluidsynth/wiki/Download

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66420621

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档