absadiki/pywhispercpp

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

Closed this issue Β· 25 comments

Original issue: #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. 

@UsernamesLame,
I don't have access to a Windows Machine to do some tests but based on #34, if you put the whisper.dll file in site-packages and used this script it should work basically!
If not, could you please use this method to check which DLL file is missing!

@abdeladim-s I tried adding the DLL, same issue. Is there a particular reason pywhispercpp doesn't auto build / come with whisper.dll?

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"))

Replace the URL in whisperdll_zip with https://github.com/ggerganov/whisper.cpp/releases/download/v1.6.0/win32-x86-64_whisper.dll.zip for the latest DLL that is much more optimized.

@abdeladim-s I tried adding the DLL, same issue. Is there a particular reason pywhispercpp doesn't auto build / come with whisper.dll?

@UsernamesLame, There was a change in the repo a while ago to build the bindings against the whisper.cpp as a target library, and so in the build process it does not copy the generated .dll file to the wheel. I tried to fix this for linux and it seems to be working, but for Windows it didn't work, I need to have access to a Windows machine to do some debuging!

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.

I'm glad you like the script. I guess I'm a contributor now πŸ˜…

It's almost midnight here (Canada) so I'm going to sleep but I did fork the repo.

I haven't worked with PD11, but I'll try and get up to speed tomorrow and submit a few pull requests.

I'm not going to lie, I'm not the best with git so please be patient when I do pull requests.

I want to help clean up this library a bit and simplify the windows experience.

Unrelated:

I also was wondering about professing multiple files in a row and if I need to re-initialize whisper or if I can reuse the in memory model without carrying contexts between files.

Sorta like serial transcribing without tainting different files from different contexts.

Any ideas on that front?

Anyways, goodnight for now. Looking forward to making some pull requests.

Of course, please go ahead, PRs are always welcome! πŸ˜„
And don't worry about git, just make sure to wrap the related changes in their specific commit so we can easily review them together.


By the way, if you succeeded in building the project from the source, could you please pull the latest commit and give it a try?
I believe I found the issue with the missing DLL and pushed a small fix. If you could also build the wheel and check if the whisper.dll file is included in the pywhispercpp/lib folder, that would be awesome!


Regarding your question:

I'm not entirely sure what you mean, but if I understand correctly, yes you can process multiple files in a row with the same model in memory, because, as far as I know, there's no concept of context here -unlike with LLMs, for example-.
However, I might be wrong, so if you run some tests and find anything related to this, please share it with me!

Of course, please go ahead, PRs are always welcome! πŸ˜„ And don't worry about git, just make sure to wrap the related changes in their specific commit so we can easily review them together.

By the way, if you succeeded in building the project from the source, could you please pull the latest commit and give it a try? I believe I found the issue with the missing DLL and pushed a small fix. If you could also build the wheel and check if the whisper.dll file is included in the pywhispercpp/lib folder, that would be awesome!

Regarding your question:

I'm not entirely sure what you mean, but if I understand correctly, yes you can process multiple files in a row with the same model in memory, because, as far as I know, there's no concept of context here -unlike with LLMs, for example-. However, I might be wrong, so if you run some tests and find anything related to this, please share it with me!

I tried to install from wheel and source, from wheel thelib folder isn't created. From source it's created, but doesn't contain whisper.dll

Also to build from source, you must have all the MSVC tools installed. I only had the compiler and it refused to build. Just a heads up on that.

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.

Of course, please go ahead, PRs are always welcome! πŸ˜„ And don't worry about git, just make sure to wrap the related changes in their specific commit so we can easily review them together.
By the way, if you succeeded in building the project from the source, could you please pull the latest commit and give it a try? I believe I found the issue with the missing DLL and pushed a small fix. If you could also build the wheel and check if the whisper.dll file is included in the pywhispercpp/lib folder, that would be awesome!
Regarding your question:
I'm not entirely sure what you mean, but if I understand correctly, yes you can process multiple files in a row with the same model in memory, because, as far as I know, there's no concept of context here -unlike with LLMs, for example-. However, I might be wrong, so if you run some tests and find anything related to this, please share it with me!

I tried to install from wheel and source, from wheel thelib folder isn't created. From source it's created, but doesn't contain whisper.dll

Also to build from source, you must have all the MSVC tools installed. I only had the compiler and it refused to build. Just a heads up on that.

Yes, you'll need MVS to compile the project, but no worries.

I set up a VM yesterday to debug it, and here is the resulting wheel: wheel.zip.
Give it a try! Extract the zip, install it in a virtual environment, and check if it works.

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.

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!

Update on the wheel:

ERROR: pywhispercpp-1.2.0-cp311-cp311-win_amd64.whl is not a supported wheel on this platform.

That's odd.

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

Update on the wheel:

ERROR: pywhispercpp-1.2.0-cp311-cp311-win_amd64.whl is not a supported wheel on this platform.

That's odd.

I think because you are using Python 3.12, The wheel is built with Python 3.11

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

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

Hell froze! IT JUST WORKED ON WINDOWS AFTER A REINSTALL FROM PIP!

I guess we can close this issue?

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!

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 πŸ˜‚

It's probably because whisper.dll is still somewhere in your environment πŸ˜…

It's probably because whisper.dll is still somewhere in your environment πŸ˜…

I made sure to delete it before re-installing! it's finally working!

It's probably because whisper.dll is still somewhere in your environment πŸ˜…

I made sure to delete it before re-installing! it's finally working!

that's wierd! It shouldn't be working, because I didn't push any new version to PyPI yet πŸ˜…

It's probably because whisper.dll is still somewhere in your environment πŸ˜…

I made sure to delete it before re-installing! it's finally working!

that's wierd! It shouldn't be working, because I didn't push any new version to PyPI yet πŸ˜…

Something you changed in one of the recent updates fixed it! Anyways, I guess we can close this one.

Yes maybe. That's a good thing anyways :)