Skip to content

Update lib path on macOS #12

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

patrick91
Copy link

Fix from #9

Basically on macOS we were trying to load the wrong file 😊

Fix from carloscdias#9

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

@wolffshots wolffshots left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solves #9 for me!

@cansik
Copy link

cansik commented Nov 8, 2023

Would be great if you could merge this, thanks!

@cansik
Copy link

cansik commented Nov 9, 2023

For everyone having the same problem on MacOS, I just wrote a hacky solution to patch the .dylib loading into the current pip package code:

import pkgutil
import re
from pathlib import Path

# patch whisper on file not find error
# https://github.com/carloscdias/whisper-cpp-python/pull/12
try:
    import whisper_cpp_python
except FileNotFoundError:
    regex = r"(\"darwin\":\n\s*lib_ext = \")\.so(\")"
    subst = "\\1.dylib\\2"

    print("fixing and re-importing whisper_cpp_python...")
    # load whisper_cpp_python and substitute .so with .dylib for darwin
    package = pkgutil.get_loader("whisper_cpp_python")
    whisper_path = Path(package.path)
    whisper_cpp_py = whisper_path.parent.joinpath("whisper_cpp.py")
    content = whisper_cpp_py.read_text()
    result = re.sub(regex, subst, content, 0, re.MULTILINE)
    whisper_cpp_py.write_text(result)

    import whisper_cpp_python

@kishorekaruppusamy
Copy link

For everyone having the same problem on MacOS, I just wrote a hacky solution to patch the .dylib loading into the current pip package code:

import pkgutil
import re
from pathlib import Path

# patch whisper on file not find error
# https://github.com/carloscdias/whisper-cpp-python/pull/12
try:
    import whisper_cpp_python
except FileNotFoundError:
    regex = r"(\"darwin\":\n\s*lib_ext = \")\.so(\")"
    subst = "\\1.dylib\\2"

    print("fixing and re-importing whisper_cpp_python...")
    # load whisper_cpp_python and substitute .so with .dylib for darwin
    package = pkgutil.get_loader("whisper_cpp_python")
    whisper_path = Path(package.path)
    whisper_cpp_py = whisper_path.parent.joinpath("whisper_cpp.py")
    content = whisper_cpp_py.read_text()
    result = re.sub(regex, subst, content, 0, re.MULTILINE)
    whisper_cpp_py.write_text(result)

    import whisper_cpp_python

Great work @cansik !!!
This Works for me also Thanks ....

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

Successfully merging this pull request may close these issues.

4 participants