Repository: wenet-e2e/wenet

Issue:
DLL load failed while importing _wenet: 找不到指定的模块。
我安装了wenet, pip install wenet.
安装提示成功了。
我用例子程序做识别。
程序如下：
import sys
import wenet

def get_text_from_wav(dir, wav):
    model_dir = dir
    wav_file = wav
    decoder = wenet.Decoder(model_dir)
    ans = decoder.decode_wav(wav_file)
    print(ans)

if __name__ == '__main__':
    dir = "./models"
    wav = "./1.wav"
    get_text_from_wav(dir,wav)

但是运行报错如下：
Traceback (most recent call last):
  File "D:\codes\speech2word\main.py", line 2, in <module>
    import wenet
  File "D:\codes\speech2word\venv\lib\site-packages\wenet\__init__.py", line 1, in <module>
    from .decoder import Decoder  # noqa
  File "D:\codes\speech2word\venv\lib\site-packages\wenet\decoder.py", line 17, in <module>
    import _wenet
ImportError: DLL load failed while importing _wenet: 找不到指定的模块。

请问如何解决？



Discussion:
同问，是这个模块还在开发的意思吗
@Mddct do you have time to figure out the problem?
> 我安装了wenet, pip install wenet.
> 安装提示成功了。
> 我用例子程序做识别。
> 程序如下：
> import sys
> import wenet
> 
> def get_text_from_wav(dir, wav):
>     model_dir = dir
>     wav_file = wav
>     decoder = wenet.Decoder(model_dir)
>     ans = decoder.decode_wav(wav_file)
>     print(ans)
> 
> if __name__ == '__main__':
>     dir = "./models"
>     wav = "./1.wav"
>     get_text_from_wav(dir,wav)
> 
> 但是运行报错如下：
> Traceback (most recent call last):
>   File "D:\codes\speech2word\main.py", line 2, in <module>
>     import wenet
>   File "D:\codes\speech2word\venv\lib\site-packages\wenet\__init__.py", line 1, in <module>
>     from .decoder import Decoder  # noqa
>   File "D:\codes\speech2word\venv\lib\site-packages\wenet\decoder.py", line 17, in <module>
>     import _wenet
> ImportError: DLL load failed while importing _wenet: 找不到指定的模块。
> 
> 请问如何解决？
> 

Which python version and window are you using?
Mine is python38 and win10.
Could you use python3.6 using virtualenv to see if it has the same problem？ I'll reproduce when my env is done
Using python 36 is ok.
我安装了python 3.6，还是报一样的错误。
I have the same issue on Windows 11 with python 3.8
opened `_wenet.cp38-win_amd64.pyd` with Dependencies. It seems `libiomp5md.dll` is required but is not available.
![image](https://user-images.githubusercontent.com/948283/173100940-66ff418e-f343-4c99-ae1d-664018bbbab0.png)


can you find this so in wheel？
@Mddct It's not in the wheel

![image](https://user-images.githubusercontent.com/948283/173107948-2721db5b-f751-4a1f-96dc-40e0927a79dc.png)

Can you download libtorch and put this so (in libtorch/lib/libiomp5md.dll) to your wheel folder to see if it can work

https://download.pytorch.org/libtorch/cpu/libtorch-win-shared-with-deps-1.10.0%2Bcpu.zip


putting `libiomp5md.dll` to the folder of `_wenet.cp38-win_amd64.pyd` works.
Thanks
> putting `libiomp5md.dll` to the folder of `_wenet.cp38-win_amd64.pyd` works.
> Thanks

@pengzhendong will  help fix tomorrow

Resolving patch:
diff --git a/runtime/binding/python/setup.py b/runtime/binding/python/setup.py
--- a/runtime/binding/python/setup.py
+++ b/runtime/binding/python/setup.py
@@ -60,12 +60,12 @@ def build_extension(self, ext: setuptools.extension.Extension):
             fst_lib = 'fc_base/openfst-build/src/lib/.libs'
             for ext in ['so', 'dylib']:
                 libs.extend(glob.glob(f'{src_dir}/{fst_lib}/libfst.{ext}'))
-            libs.extend(glob.glob(f'{src_dir}/{torch_lib}/libgomp*'))  # linux
-            libs.extend(glob.glob(f'{src_dir}/{torch_lib}/libiomp*'))  # macos
         else:
             libs.extend(glob.glob(f'{src_dir}/{torch_lib}/asmjit.dll'))
             libs.extend(glob.glob(f'{src_dir}/{torch_lib}/fbgemm.dll'))
             libs.extend(glob.glob(f'{src_dir}/{torch_lib}/uv.dll'))
+        libs.extend(glob.glob(f'{src_dir}/{torch_lib}/libgomp*'))  # linux
+        libs.extend(glob.glob(f'{src_dir}/{torch_lib}/libiomp5*'))  # macos/win
 
         for lib in libs:
             print(f"Copying {lib} to {self.build_lib}/")


Test patch: