nwhitehead / pyfluidsynth

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

Add fix to locate Homebrew-installed libfluidsynth #69

Closed ideoforms closed 3 weeks ago

ideoforms commented 1 month ago

On macOS on Apple silicon, non-Homebrew Python distributions fail to locate homebrew-installed instances of FluidSynth and raise an ImportError("Couldn't find the FluidSynth library."). This workaround addresses this.

Thanks for the great library!

cclauss commented 1 month ago

https://github.com/nwhitehead/pyfluidsynth/blob/master/.github/workflows/ci.yml#L30-L33

ideoforms commented 1 month ago

Thanks for the reply. Setting DYLD_LIBRARY_PATH before running the script is the alternative workaround, and what I was using previously. However, this imposes an additional requirement that would need to be set up by the user in each different environment they're using pyfluidsynth in, and I think it's helpful to let the library handle this for the user.

Let me know if you're happy to potentially merge this, and I will address the codespell_and_ruff issues.

ideoforms commented 2 weeks ago

Thanks @cclauss! Just tested and unfortunately the revised version does not work; the HOMEBREW_PREFIX environmental variable isn't always set unless your terminal is set up to explicitly evaluate brew shellenv, which mine isn't. So brew --prefix is the canonical way to achieve this.

cclauss commented 2 weeks ago

You can either evaluate https://docs.brew.sh/Manpage#shellenv-shell- or export HOMEBREW_PREFIX=$(brew --prefix)

Improperly installing homebrew seems suboptimal in any case.

ideoforms commented 2 weeks ago

Configuring shellenv isn't part of the installation process, though; I have installed Homebrew on dozens of macOS systems over the years, and this isn't something that is required for any other package I've encountered.

I'd see the additional step of setting HOMEBREW_PREFIX as similar to the earlier workaround with DYLD_LIBRARY_PATH: a user absolutely could do this, but it's not easily discoverable and would require some extra research/documentation at setup time, which many users just won't get past. I think these small quality of life features make a package much more frictionless and attractive in general.

pyfluidsynth is a great package, and it would be nice if installing and using it was as simple as a one-liner pip install for all users.