I get the following error when trying to import the librosa library into my python project and running it in the global python environment:

Traceback (most recent call last):   File
"/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/soundfile.py",
line 142, in 
raise OSError('sndfile library not found') OSError: sndfile library not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):   File
"Bloompipe/Synthesis_Module/bloompipe_synthesis/testSynthesis.py",
line 6, in 
from LSD.lucidsonicdreams import LucidSonicDream   File "Bloompipe/Synthesis_Module/bloompipe_synthesis/LSD/lucidsonicdreams/init.py",
line 1, in 
from .main import *   File "Bloompipe/Synthesis_Module/bloompipe_synthesis/LSD/lucidsonicdreams/main.py",
line 15, in 
from .AudioAnalyse import *   File "Bloompipe/Synthesis_Module/bloompipe_synthesis/LSD/lucidsonicdreams/AudioAnalyse.py",
line 3, in 
import librosa.display   File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/librosa/init.py",
line 209, in 
from . import core   File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/librosa/core/init.py",
line 6, in 
from .audio import *  # pylint: disable=wildcard-import   File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/librosa/core/audio.py",
line 8, in 
import soundfile as sf   File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/soundfile.py",
line 162, in 
_snd = _ffi.dlopen(_os.path.join( OSError: cannot load library '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/_soundfile_data/libsndfile.dylib':
dlopen(/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/_soundfile_data/libsndfile.dylib,
0x0002): tried:
'/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/_soundfile_data/libsndfile.dylib'
(no such file)
Process finished with exit code 1

I installed the libsndfile library with homebrew and also for a virtual conda environment. When trying to run the program in the conda environment it produces the following error:

Traceback (most recent call last):   File
".conda/envs/bloompipe_synthesis/lib/python3.9/site-packages/soundfile.py",
line 143, in 
_snd = _ffi.dlopen(_libname) OSError: cannot load library '.conda/envs/bloompipe_synthesis/bin/../lib/libsndfile.dylib':
dlopen(.conda/envs/bloompipe_synthesis/bin/../lib/libsndfile.dylib,
0x0002): Library not loaded: @rpath/libvorbis.0.4.9.dylib   Referenced
from:
.conda/envs/bloompipe_synthesis/lib/libsndfile.1.0.31.dylib
Reason: tried:
'.conda/envs/bloompipe_synthesis/lib/libvorbis.0.4.9.dylib'
(no such file),
'.conda/envs/bloompipe_synthesis/lib/libvorbis.0.4.9.dylib'
(no such file),
'.conda/envs/bloompipe_synthesis/lib/libvorbis.0.4.9.dylib'
(no such file),
'.conda/envs/bloompipe_synthesis/lib/libvorbis.0.4.9.dylib'
(no such file),
'.conda/envs/bloompipe_synthesis/lib/python3.9/site-packages/../../libvorbis.0.4.9.dylib'
(no such file),
'.conda/envs/bloompipe_synthesis/lib/libvorbis.0.4.9.dylib'
(no such file),
'.conda/envs/bloompipe_synthesis/bin/../lib/libvorbis.0.4.9.dylib'
(no such file), '/usr/local/lib/libvorbis.0.4.9.dylib' (no such file),
'/usr/lib/libvorbis.0.4.9.dylib' (no such file)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):   File
"Bloompipe/Synthesis_Module/bloompipe_synthesis/testSynthesis.py",
line 6, in 
from LSD.lucidsonicdreams import LucidSonicDream   File "Bloompipe/Synthesis_Module/bloompipe_synthesis/LSD/lucidsonicdreams/init.py",
line 1, in 
from .main import *   File "Bloompipe/Synthesis_Module/bloompipe_synthesis/LSD/lucidsonicdreams/main.py",
line 15, in 
from .AudioAnalyse import *   File "Bloompipe/Synthesis_Module/bloompipe_synthesis/LSD/lucidsonicdreams/AudioAnalyse.py",
line 3, in 
import librosa.display   File ".conda/envs/bloompipe_synthesis/lib/python3.9/site-packages/librosa/init.py",
line 209, in 
from . import core   File ".conda/envs/bloompipe_synthesis/lib/python3.9/site-packages/librosa/core/init.py",
line 6, in 
from .audio import *  # pylint: disable=wildcard-import   File ".conda/envs/bloompipe_synthesis/lib/python3.9/site-packages/librosa/core/audio.py",
line 8, in 
import soundfile as sf   File ".conda/envs/bloompipe_synthesis/lib/python3.9/site-packages/soundfile.py",
line 162, in 
_snd = _ffi.dlopen(_os.path.join( OSError: cannot load library '.conda/envs/bloompipe_synthesis/lib/python3.9/site-packages/_soundfile_data/libsndfile.dylib':
dlopen(.conda/envs/bloompipe_synthesis/lib/python3.9/site-packages/_soundfile_data/libsndfile.dylib,
0x0002): tried:
'.conda/envs/bloompipe_synthesis/lib/python3.9/site-packages/_soundfile_data/libsndfile.dylib'
(no such file)
Process finished with exit code 1

The thing is that in both cases it is looking for the .dylib files in the wrong directories. My homebrew installation is in /opt/homebrew/lib and has the files libsndfile.dylib and libsndfile.1.dylib in it and also the libvorbis.dylib file. When trying to run on the global python environment it is looking for those files in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/_soundfile_data/ though.
My conda installation is in /opt/anaconda3/lib and has the files libsndfile.dylib, libsndfile.1.0.31.dylib and libsndfile.1.dylib in it and also the libvorbis.dylib and libvorbis.0.4.9.dylib file. When trying to run on the conda python environment it is looking for those files in .conda/envs/bloompipe_synthesis/lib/python3.9/site-packages/_soundfile_data/.
In both cases when looking in those site-packages directories, the _soundfile_data folder doesn't exist even when activating the hidden files. I don't know why that doesn't exist.
I tried executing:

export CPATH=/opt/homebrew/include
export LIBRARY_PATH=/opt/homebrew/lib
export PYTHONPATH=/opt/homebrew/lib

To include the paths into the python path when running
Then I printed the path variables with import sys and print(sys.path), this was the output for my global python:

['Bloompipe/Synthesis_Module/bloompipe_synthesis',
'Bloompipe/Synthesis_Module/bloompipe_synthesis',
'/Library/Frameworks/Python.framework/Versions/3.9/lib/python39.zip',
'/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9',
'/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload',
'/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages',
'opt/homebrew/lib']

And for the conda environment I tried:

conda develop .conda/envs/bloompipe_synthesis/lib
conda develop /opt/homebrew/lib
conda develop /opt/anaconda3/lib

Then the sys.path output is:

['Bloompipe/Synthesis_Module/bloompipe_synthesis',
'.conda/envs/bloompipe_synthesis/lib/python39.zip',
'.conda/envs/bloompipe_synthesis/lib/python3.9',
'.conda/envs/bloompipe_synthesis/lib/python3.9/lib-dynload',
'.conda/envs/bloompipe_synthesis/lib/python3.9/site-packages',
'.conda/envs/bloompipe_synthesis/lib',
'/opt/homebrew/lib',
'/opt/anaconda3/lib']

Weirdly, python is still not looking in those directories when executing the librosa import.
Finally, I tried adding the path to the homebrew installation manually by putting sys.path.append("/opt/homebrew/lib") in the beginning of the python file. It still produces the exact same errors.
So my question is, why does the _soundfile_data directory not exist in my site-packages folders for the global python and the conda environment and why doesn't it include the .dylib files for libsndfile?
Secondly, why does:

export LIBRARY_PATH=/opt/homebrew/lib
export PYTHONPATH=/opt/homebrew/lib

not do that those paths appear when printing the sys.path content?
Thirdly, why does python not find the libsndfile.dylib files with the conda environment, even though I added the homebrew and the conda installation of libsndfile to the sys path with the conda develop command?
My python3.9 is installed in /usr/local/bin/python3.9 and my conda python3.9 environment is installed in /.conda/envs/bloompipe_synthesis/bin/python
I'm on a new mac with Mac OS Monterey.
Any help is greatly appreciated!
As far as I know it only works with python 3.6 and 3.7 (lucidsonicdreams), although I didn't have success on 3.6.
I had to create a virtual environment through conda and run code through Jupyter notebook. conda install tensorflow==1.15 (will not work with higher versions), python==3.7, pip install lucidsonicdreams in your new python 3.7 environment.
Make sure module versions line up with your Nvidia CUDA drivers or lucidsonicdreams won't work.
Python linking to wrong library folder - sndfile library not found