nwhitehead / pyfluidsynth

Python bindings for FluidSynth
GNU Lesser General Public License v2.1
197 stars 56 forks source link

ImportError: Couldn't find the FluidSynth library. #30

Closed LeonhWolf closed 3 years ago

LeonhWolf commented 3 years ago

Hi guys, I cloned the pyfluidsynth as a submodule into my repository. After that I followed the install instructions by running "python setup.py install". That was also completed successfully. I also downloaded fluidsynth-2.1.6-win10-x64.zip. However, when I run the code of test.test1.py I get the following error:

Traceback (most recent call last): File "d:\Documents\05_programData\01_GitRepos\metronome\c_MIDIPlayback.py", line 2, in from a_Libraries import fluidsynth File "d:\Documents\05_programData\01_GitRepos\metronome\a_Libraries\fluidsynth.py", line 42, in raise ImportError("Couldn't find the FluidSynth library.") ImportError: Couldn't find the FluidSynth library.

I tried tracing it back following line 42 in fluidsynth.py. But since I'm pretty new to Python I lost track pretty quickly. Googling also didn't bring up anything useful.

I'd be super happy about help! And thanks for the (probably, couldn't really test it yet :D) cool library!

software details

albedozero commented 3 years ago

The script tries to figure out where fluidsynth is installed on its own, but for Windows there isn't an installer that makes this known as there is on other systems. You can either put fluidsynth.py in the same directory as where you installed Fluidsynth, or add the location of Fluidsynth to your PATH environment variable (type "edit the system environment variables" into the search bar).

LeonhWolf commented 3 years ago

Thanks for your rapid answer!

I added the location of Fluidsynth to my PATH environment variable (c:\users\myuser\appdata\local\programs\python\python37\lib\site-packages). Additionally, I added the .egg file to my repository. But I still get the same error. Have a look at the screenshot of my project folder below:

image

The file at the bottom is the .egg.

Do you have any other suggestion? Am I missing something?

albedozero commented 3 years ago

Oops, let me clarify - I meant add the location of where you unzipped the contents of fluidsynth-2.1.6-win10-x64.zip to PATH. That will allow the find_library function in fluidsynth.py to locate the libfluidsynth-2.dll that it needs.

LeonhWolf commented 3 years ago

Thanks! Adding the location of the library to PATH didn't work. But copying the file fluidsynth-2.1.6-win10-x64.bin.libfluidsynth-2.dll solved the ImportError.

image

But now I get the error:

Traceback (most recent call last): File "d:\Documents\05_programData\01_GitRepos\metronome\c_MIDIPlayback.py", line 2, in from a_Libraries import fluidsynth File "d:\Documents\05_programData\01_GitRepos\metronome\a_Libraries\fluidsynth.py", line 46, in _fl = CDLL(lib) File "C:\Users\leonh\AppData\Local\Programs\Python\Python37\lib\ctypes__init.py", line 364, in init__ self._handle = _dlopen(self._name, mode) OSError: [WinError 126] The specified module could not be found

I tried the following bugfixes I found online:

Didn't fix it.

Sorry to bother you so long. But this library seems to be the only one where you can play midi and change the soundfonts.

ChristianRomberg commented 3 years ago

No worries. Is the architecture of the library correct (32 or 64 bit?)? Are there library dependencies (other DLLs from the zip archive) which you didn't copy?

Click here if you're unsure whether you're missing dependency libs Did you copy the whole contents of the bin folder from the fluidsynth zip archive? I'm thinking that all the other libraries in there are dependencies which also need to be in the PATH or in the folder you're executing from

albedozero commented 3 years ago

It actually needs all of the DLLs included in the fluidsynth .zip, specifically

libfluidsynth-2.dll
libglib-2.0-0.dll
libgobject-2.0-0.dll
libgthread-2.0-0.dll
libinstpatch-2.dll
libintl-8.dll
libsndfile-1.dll

If you copy all those it should work. Not sure why setting your PATH environment variable isn't working, though - maybe I closed this issue prematurely. You could also try cough albedozero/fluidpatcher - the setup executable in the release installs FluidSynth and sets your environment variables appropriately.

LeonhWolf commented 3 years ago

I tried copying all .dll files into the project folder. This worked perfectly.

Thanks for your support @albedozero and @ChristianRomberg!