pywhispercpp: Fix for "_pywhispercpp module could not be found" didn't fix module could not be found.

Original issue: https://github.com/abdeladim-s/pywhispercpp/issues/34

I’m having the same issue when using pip install pywhispercpp despite it successfully installing. Seems like something is broken on windows still.

DLL load failed while importing _pywhispercpp: The specified module could not be found.
  File "C:\Users\user\Desktop\faster-whisper\main.py", line 1, in <module>
    from pywhispercpp.model import Model
ImportError: DLL load failed while importing _pywhispercpp: The specified module could not be found.```

Any advice would be helpful. I tried adding the whisper.dll as advised in issue 34, it didn't fix it. Reinstalled the package, same issue. 

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 25 (25 by maintainers)

Commits related to this issue

Most upvoted comments

Yes maybe. That’s a good thing anyways 😃

Nice 👍

The wheel I provided worked ? Or the wheel from PyPI ?

If you have a gpu accelerator, can you test if it’s working ? the wheel I provided is compiled with Vulkan!

The wheel from PyPi. I tried it first. I was shocked how it instantly worked 😂

I tried cloning from git and installing the latest build.

Could not find module 'c:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\pywhispercpp\lib\_pywhispercpp.cp312-win_amd64.pyd' (or one of its dependencies). Try using the full path with constructor syntax.
  File "C:\Users\Felix\Desktop\faster-whisper\main.py", line 1, in <module>
    from pywhispercpp.model import Model
FileNotFoundError: Could not find module 'c:\Users\Felix\AppData\Local\Programs\Python\Python312\Lib\site-packages\pywhispercpp\lib\_pywhispercpp.cp312-win_amd64.pyd' (or one of its dependencies). Try using the full path with constructor syntax.

Seems like the windows install is extremely finicky

Always Windows like this 😅


I think it’s the famous whisper.dll file as usual. However, pulling the latest changes should resolve it basically. The GitHub action for windows completed successfully as well, and here is the resulting wheel for Python 3.12.wheel.zip

I tried cloning from git and installing the latest build.

Could not find module 'c:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\pywhispercpp\lib\_pywhispercpp.cp312-win_amd64.pyd' (or one of its dependencies). Try using the full path with constructor syntax.
  File "C:\Users\Felix\Desktop\faster-whisper\main.py", line 1, in <module>
    from pywhispercpp.model import Model
FileNotFoundError: Could not find module 'c:\Users\Felix\AppData\Local\Programs\Python\Python312\Lib\site-packages\pywhispercpp\lib\_pywhispercpp.cp312-win_amd64.pyd' (or one of its dependencies). Try using the full path with constructor syntax.

Seems like the windows install is extremely finicky

Reading through d452d8b, I have a feeling dll_files = os.path.join(self.build_temp, 'bin', 'Release', '*.dll') is the offending line. Shouldn’t it be Release then bin? Let me check how it built on my computer. I’m really not a C++ person so this is like speaking french to me, and I’m not a Québécois. Edit: I think my blind stab in the dark hit the mark! \pywhispercpp\build\temp.win-amd64-cpython-312\Release\_pywhispercpp\bin\Release So it should be dll_files = os.path.join(self.build_temp, 'Release', '_pywhispercpp', 'bin', 'Release', '*.dll') if I am right. Let me quickly patch my local copy. Edit: Patch didn’t work. Let me actually read setup.py fully before patching it. Edit 2: Somewhere along the way we’re losing the temp build directory / getting the wrong directory, I’m not sure why or how. Like, it is building the DLL but then failing to copy it. Edit 3: So this is definitely outside of my comfort zone, but I can tell you that whisper.dll needs to be copied to pywhispercpp/lib now instead of site packages breaking my old script.

It’s okay, Thanks for the time you put into this. I believe the folder is correct, at least based on yesterday’s debugging.

I think your script will still work if someone installs the library from PyPI. Until the next release, the whisper.dll should go into the lib folder so it will be loaded at runtime.

Thank you for the kind words. Let me try that new wheel you made and report back!

Reading through d452d8b, I have a feeling dll_files = os.path.join(self.build_temp, 'bin', 'Release', '*.dll') is the offending line.

Shouldn’t it be Release then bin? Let me check how it built on my computer. I’m really not a C++ person so this is like speaking french to me, and I’m not a Québécois.

Edit:

I think my blind stab in the dark hit the mark!

\pywhispercpp\build\temp.win-amd64-cpython-312\Release\_pywhispercpp\bin\Release

So it should be

dll_files = os.path.join(self.build_temp, 'Release', '_pywhispercpp', 'bin', 'Release', '*.dll')

if I am right. Let me quickly patch my local copy.

Edit:

Patch didn’t work. Let me actually read setup.py fully before patching it.

Edit 2:

Somewhere along the way we’re losing the temp build directory / getting the wrong directory, I’m not sure why or how. Like, it is building the DLL but then failing to copy it.

Edit 3:

So this is definitely outside of my comfort zone, but I can tell you that whisper.dll needs to be copied to pywhispercpp/lib now instead of site packages breaking my old script.

It’s okay, Thanks for the time you put into this. I believe the folder is correct, at least based on yesterday’s debugging.

I think your script will still work if someone installs the library from PyPI. Until the next release, the whisper.dll should go into the lib folder so it will be loaded at runtime.

Ok, so I miss-read what was written and put the DLL in pywhispercpp’s folder, it works in site-packages

However, this is a ABSOLUTELY DISGUSTING FIX so being the Python developer I am, I wrote a EQUALLY DISGUSTING fix.

from urllib.request import urlopen
from pathlib import Path
from zipfile import ZipFile
from io import BytesIO
import pywhispercpp

whisperdll_zip = BytesIO()

whisperdll_zip.write(urlopen("https://github.com/ggerganov/whisper.cpp/releases/download/v1.5.4/win32-x86-64_whisper.dll.zip").read())
whisperdll_zip.seek(0)

with ZipFile(whisperdll_zip) as whisper:

    with open(Path(pywhispercpp.__path__[0]).absolute().with_name("whisper.dll"), "wb") as file:
        file.write(whisper.read("whisper.dll"))

This auto installs it to site-packages. And in the event you do want to include this as a helper script, I’m licensing it also under the MIT license. It’s my way of saying thanks for developing pywhispercpp 😃

Thank you very much for taking the time to write the fix, it’s not disgusting at all 😅 But, we need to find a way to include the dll -against which the package was built- with the wheel.

Let’s keep this issue open, others will find the script useful for sure, at least until a good fix is pushed.

Ok, so I miss-read what was written and put the DLL in pywhispercpp’s folder, it works in site-packages

However, this is a ABSOLUTELY DISGUSTING FIX so being the Python developer I am, I wrote a EQUALLY DISGUSTING fix.

from urllib.request import urlopen
from pathlib import Path
from zipfile import ZipFile
from io import BytesIO
import pywhispercpp

whisperdll_zip = BytesIO()

whisperdll_zip.write(urlopen("https://github.com/ggerganov/whisper.cpp/releases/download/v1.5.4/win32-x86-64_whisper.dll.zip").read())
whisperdll_zip.seek(0)

with ZipFile(whisperdll_zip) as whisper:

    with open(Path(pywhispercpp.__path__[0]).absolute().with_name("whisper.dll"), "wb") as file:
        file.write(whisper.read("whisper.dll"))

This auto installs it to site-packages. And in the event you do want to include this as a helper script, I’m licensing it also under the MIT license. It’s my way of saying thanks for developing pywhispercpp 😃

Edit:

I just realized this worked for me because I had whisper.dll installed manually. The original script would break otherwise. Here’s a revised version for anyone stumbling upon this:

from urllib.request import urlopen
from pathlib import Path
from zipfile import ZipFile
from io import BytesIO
import pip

whisperdll_zip = BytesIO()

whisperdll_zip.write(urlopen("https://github.com/ggerganov/whisper.cpp/releases/download/v1.6.0/win32-x86-64_whisper.dll.zip").read())
whisperdll_zip.seek(0)

with ZipFile(whisperdll_zip) as whisper:

    with open(Path(pip.__path__[0]).absolute().with_name("whisper.dll"), "wb") as file:
        file.write(whisper.read("whisper.dll"))