4

I'm trying to install pyfluidsynth on windows. I used pip install pyfluidsynth in the command prompt, but when I tried to import fluidsynth in my python code I get:

 ModuleNotFoundError: No module named 'FluidSynth'

When I tried to install FluidSynth (by using pip install fluidsynth) another binding package was installed with FluidSynth 0.2 from several years ago.

Can anybody help with specific details on how to install pyfluidsynth on windows and use it?

import FluidSynth

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Program Files\JetBrains\PyCharm 2018.3.2\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'FluidSynth'
Garam Lee
  • 147
  • 12
david
  • 61
  • 1
  • 4

4 Answers4

2

For recent FluidSynth versions there do not seem to be pre-built binaries for ms-windows available. (Note that development is now done on github; the sourceforge site is stale.) The latest source code releases are here.

But the FluidSynth wiki has instructions for building it on ms-windows.

Note: FluidSynth (more precisely, its shared library) is a requirement for using pyfluidsynth. See the README.

Roland Smith
  • 42,427
  • 3
  • 64
  • 94
  • Thanks. Since I wish to use pyfluidsynth I wonder if the pre installation of fluidsynth is a must. Moreover, what is the recommended installation for using pyfluidsynth (what is required in order to use the command "import fluidsynth" after "pip install pyfluidsynth". – david Jan 13 '19 at 12:09
  • @david See updated answer. If you look at the shared library link, you will see that `pyfluidsynth` raises `ImportError` when it cannot locate FluidSynth's shared library. – Roland Smith Jan 13 '19 at 12:40
  • Thank you. I worked hard to install Fluidsynth using MinGW and I finally succeeded. I can run Fluidsynth.exe and I got libfluidsynth-2.dll file (not libfluidsynth-1.dll). I changed the file name to libfluidsynth-1.dll and put it in the project main directory (I work with pyCharm). I got an error while running it: OSError: [WinError 193] %1 is not a valid Win32 application. Any idea? – david Jan 15 '19 at 06:34
  • @david That error typically occurs when a program tries to start a program whose location is not in the `$PATH`. The `%1` should be the name of the program, but windows doesn't fill it in. – Roland Smith Jan 15 '19 at 07:24
  • @david : have you been successful to run pyFluiSynth meanwhile ? I have run into the same problems you have stated here (https://stackoverflow.com/questions/56209587/how-to-install-pyfluidsynth-on-win10) – pyano May 20 '19 at 07:04
2

For me the following worked:

  1. Go to the following link and download the pre-compiled (?) fluidsynth dll.
  2. Add the directory of your fluidsynth dll to the path environment variable.
  3. In the pyfluidsynth package. find the "fluidsynth.py" file, and edit the part where it's looking for the library "lib = find_library('fluidsynth')..." to search for the dll name, which was "libfluidsynth64" for the 64 bit version.
  4. For whatever reason, (maybe version mismatch), the functions "fluid_synth_set_reverb_full" and "fluid_synth_set_chorus_full" are not supported, so comment those lines out from "fluidsynth.py".
  5. And that's it. Save "fluidsynth.py" launch cmd, go into python, and import fluidsynth.

I haven't tested all the functionality of fluidsynth, but using pretty_midi, I was able to at least play midi through instrument soundfonts.

Hope this helps!

David García Bodego
  • 1,058
  • 3
  • 13
  • 21
Abraxas Yu
  • 31
  • 4
0

Installing fluidsynth on Windows

Download fluidsynth binaries from github: https://github.com/FluidSynth/fluidsynth/releases

Add extracted zip file’s bin to the path: Eg: C:\Users*Your Username Here**** YOUR path to extracted zip ***\fluidsynth-2.1.6-win10-x64\bin

Download fluidsynth python library: the repository for python fluidsynth is: https://github.com/nwhitehead/pyfluidsynth. https://github.com/nwhitehead/pyfluidsynth/archive/master.zip

Once extracted, it must be installed:

python setup.py install

The extracted master.zip has fluidsynth.py This python file is the file to “import” into the python code. In the test folder it has example.sf2 which is used in an installation test: paths to these two files need to be set to your own locations.

import time
import fluidsynth

fs = fluidsynth.Synth()
fs.start()

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

fs.noteon(0, 60, 30)
fs.noteon(0, 67, 30)
fs.noteon(0, 76, 30)

time.sleep(1.0)

fs.noteoff(0, 60)
fs.noteoff(0, 67)
fs.noteoff(0, 76)

time.sleep(1.0)

fs.delete()

The above python code sample plays a single note. Getting this to work confirms everything is working.

ThisIsNotMe
  • 349
  • 2
  • 10
0

For me, next works:

  1. Call pip install --upgrade pyfluidsynth
  2. Download precompiled DLL from: https://zdoom.org/downloads#Support
  3. If you use 64x version rename file from libfluidsynth64.dll to libfluidsynth.dll
  4. Place it into C:\Windows\System32