Skip to content

FileNotFoundError: Shared library with base name 'whisper' not found #9

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
DamienDabernat opened this issue May 19, 2023 · 8 comments
Closed

Comments

@DamienDabernat
Copy link

Hello, thanks for your work !

I'm not the best in python and I have some trouble to install this module.

I use miniconda3 on a Macbook M1. I can install this module with pip with no problem. But when I try to import the module, there is an error : FileNotFoundError: Shared library with base name 'whisper' not found .

Here's the stack trace :

Python 3.10.11 (main, Apr 20 2023, 13:58:42) [Clang 14.0.6 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from whisper_cpp_python import Whisper
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/damien/miniconda3/envs/whisper/lib/python3.10/site-packages/whisper_cpp_python/__init__.py", line 1, in <module>
    from .whisper import *
  File "/Users/damien/miniconda3/envs/whisper/lib/python3.10/site-packages/whisper_cpp_python/whisper.py", line 1, in <module>
    from . import whisper_cpp
  File "/Users/damien/miniconda3/envs/whisper/lib/python3.10/site-packages/whisper_cpp_python/whisper_cpp.py", line 54, in <module>
    _lib = _load_shared_library(_lib_base_name)
  File "/Users/damien/miniconda3/envs/whisper/lib/python3.10/site-packages/whisper_cpp_python/whisper_cpp.py", line 45, in _load_shared_library
    raise FileNotFoundError(
FileNotFoundError: Shared library with base name 'whisper' not found

Do I missing something obvious ?

@carloscdias
Copy link
Owner

Hi @DamienDabernat , thanks for the report!

You have done everything right, it is actually a bug of locating the lib, currently the system is looking for a lib with *.dylib extension for macos systems but it is actually being created with the suffix *so, I will fix it and let you know.

Int the meantime you can try doing

import whisper_cpp_python.whisper_cpp as wc
wc._load_shared_library('whisper.so')

And see if you can then use the module

@DamienDabernat
Copy link
Author

DamienDabernat commented May 20, 2023

Hi, thanks for your reply!

I didn't succeed in making this work with :

import whisper_cpp_python.whisper_cpp as wc
wc._load_shared_library('whisper.so')

But with your help, I was able to make some advancement. I have cloned this repository and in the file whisper_cpp.py I changed this line :

# Specify the base name of the shared library to load
_lib_base_name = "libwhisper"

And :

# Specify the base name of the shared library to load
    elif sys.platform == "darwin":
        lib_ext = ".dylib"

With this done, I was nearly capable of importing the correct lib, but the script failed at the import of librosa lib.

I was capable of fixing this by installing the lib as follows :

conda install -c numba numba
conda install -c conda-forge librosa

This worked. Then, when I was trying to transcribe some audio, I'm facing this error :

Library not loaded: @rpath/liblapack.3.dylib. After some searching, I found that the problem was sklearnnot correctly installed. But with python 3.10 I didn't succeed to install it.

So, I managed to install python 3.9 :

# Create new environment
conda create -n tensorflow python=3.9
conda activate tensorflow

# Install tensorflow + scikit-learn
conda install -c apple tensorflow-deps
python -m pip install tensorflow-macos
python -m pip install tensorflow-metal
python -m pip install scikit-learn

# Check import works
python -c "import sklearn"

Then re-install librosa. After all of this, I have one more issue :

whisper_init_from_file_no_state: loading model from './vendor/whisper.cpp/models/ggml-small.bin'
whisper_model_load: loading model
whisper_model_load: n_vocab       = 51865
whisper_model_load: n_audio_ctx   = 1500
whisper_model_load: n_audio_state = 768
whisper_model_load: n_audio_head  = 12
whisper_model_load: n_audio_layer = 12
whisper_model_load: n_text_ctx    = 448
whisper_model_load: n_text_state  = 768
whisper_model_load: n_text_head   = 12
whisper_model_load: n_text_layer  = 12
whisper_model_load: n_mels        = 80
whisper_model_load: ftype         = 1
whisper_model_load: type          = 3
whisper_model_load: mem required  =  743.00 MB (+   16.00 MB per decoder)
whisper_model_load: adding 1608 extra tokens
whisper_model_load: model ctx     =  464.56 MB
whisper_model_load: model size    =  464.44 MB
whisper_init_state: kv self size  =   15.75 MB
whisper_init_state: kv cross size =   52.73 MB
Exception ignored from cffi callback <function SoundFile._init_virtual_io.<locals>.vio_read at 0x287d13b80>:
Traceback (most recent call last):
  File "/Users/damien/miniconda3/envs/tensorflow/lib/python3.9/site-packages/soundfile.py", line 1248, in vio_read
    data = file.read(count)
  File "/Users/damien/miniconda3/envs/tensorflow/lib/python3.9/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 24: invalid start byte
Traceback (most recent call last):
  File "/Users/damien/Documents/Developpement/Python/whisper-cpp-python/test.py", line 3, in <module>
    output = whisper.transcribe(open('./vendor/whisper.cpp/samples/jfk.wav'))
  File "/Users/damien/Documents/Developpement/Python/whisper-cpp-python/whisper_cpp_python/whisper.py", line 21, in transcribe
    data, sr = librosa.load(file, sr=Whisper.WHISPER_SR)
  File "/Users/damien/miniconda3/envs/tensorflow/lib/python3.9/site-packages/librosa/core/audio.py", line 186, in load
    raise exc
  File "/Users/damien/miniconda3/envs/tensorflow/lib/python3.9/site-packages/librosa/core/audio.py", line 176, in load
    y, sr_native = __soundfile_load(path, offset, duration, dtype)
  File "/Users/damien/miniconda3/envs/tensorflow/lib/python3.9/site-packages/librosa/core/audio.py", line 209, in __soundfile_load
    context = sf.SoundFile(path)
  File "/Users/damien/miniconda3/envs/tensorflow/lib/python3.9/site-packages/soundfile.py", line 658, in __init__
    self._file = self._open(file, mode_int, closefd)
  File "/Users/damien/miniconda3/envs/tensorflow/lib/python3.9/site-packages/soundfile.py", line 1216, in _open
    raise LibsndfileError(err, prefix="Error opening {0!r}: ".format(self.name))
soundfile.LibsndfileError: Error opening <_io.TextIOWrapper name='./vendor/whisper.cpp/samples/jfk.wav' mode='r' encoding='UTF-8'>: Format not recognised.

I don't understand this error, do you have any idea?

Thanks for your time!

@devilteo911
Copy link

@DamienDabernat don't know if you've solved but have you checked if ffmpeg was correctly installed in your system? Because I was about to comment this thread since I had the same error occurring but I manage to solve it in this way:

elif sys.platform == "darwin":
    lib_ext = ".dylib"

without renaming this _lib_base_name = "libwhisper" as you did. I think it is unnecessary since here:

_lib_paths = [
        _base_path / f"lib{lib_base_name}{lib_ext}",
        _base_path / f"{lib_base_name}{lib_ext}",
    ]

the "lib" prefix is attached to the base. I know that your modification is not breaking the code, but I thought it worth to mention it.

After that I was able to correctly load the model and to perform inference correctly.

@vvvm23
Copy link

vvvm23 commented Jul 19, 2023

Hi @DamienDabernat , thanks for the report!

You have done everything right, it is actually a bug of locating the lib, currently the system is looking for a lib with *.dylib extension for macos systems but it is actually being created with the suffix *so, I will fix it and let you know.

Int the meantime you can try doing

import whisper_cpp_python.whisper_cpp as wc
wc._load_shared_library('whisper.so')

And see if you can then use the module

Hey @carloscdias , this fix won't work as the error is thrown on the import line itself. Do you have any other workarounds?

@DamienDabernat
Copy link
Author

@devilteo911 Yes ffmpeg is correctly installed but the error Format not recognised persists.

I'm going to investigate more this evening.

@DamienDabernat
Copy link
Author

I found the problem!
The previous fix still relevant, but I also need to specify in which mode the input audio file must be.

output = whisper.transcribe(open('./vendor/whisper.cpp/samples/jfk.wav', mode='rb'))

So, adding mode='rb' solves the final problem.

patrick91 added a commit to patrick91/whisper-cpp-python that referenced this issue Aug 24, 2023
Fix from carloscdias#9

Basically on macOS we were trying to load the wrong file 😊
@fakerybakery
Copy link

Hi,
I'm still experiencing this issue when importing it:

>>> import whisper_cpp_python.whisper_cpp as wc
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "[]site-packages/whisper_cpp_python/__init__.py", line 1, in <module>
    from .whisper import *
  File "[]site-packages/whisper_cpp_python/whisper.py", line 1, in <module>
    from . import whisper_cpp
  File "[]site-packages/whisper_cpp_python/whisper_cpp.py", line 54, in <module>
    _lib = _load_shared_library(_lib_base_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[]site-packages/whisper_cpp_python/whisper_cpp.py", line 45, in _load_shared_library
    raise FileNotFoundError(
FileNotFoundError: Shared library with base name 'whisper' not found

Is there any way to fix this?
cc: @carloscdias @DamienDabernat

@kishorekaruppusamy
Copy link

Hi, I'm still experiencing this issue when importing it:

>>> import whisper_cpp_python.whisper_cpp as wc
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "[]site-packages/whisper_cpp_python/__init__.py", line 1, in <module>
    from .whisper import *
  File "[]site-packages/whisper_cpp_python/whisper.py", line 1, in <module>
    from . import whisper_cpp
  File "[]site-packages/whisper_cpp_python/whisper_cpp.py", line 54, in <module>
    _lib = _load_shared_library(_lib_base_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[]site-packages/whisper_cpp_python/whisper_cpp.py", line 45, in _load_shared_library
    raise FileNotFoundError(
FileNotFoundError: Shared library with base name 'whisper' not found

Is there any way to fix this? cc: @carloscdias @DamienDabernat

#12 (comment)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants