Windows10下PyCharm导入Whisper报错:find_library('c')返回None
解决Windows下Whisper导入时
find_library('c')返回None的问题 问题场景
- 系统:Windows 10
- Python版本:3.9.9
- 触发错误:在PyCharm中导入whisper库时,因
whisper.py第70行的libc_name = ctypes.util.find_library('c')返回None,导致后续ctypes.CDLL(libc_name)抛出TypeError。
运行代码(main.py)
import whisper if __name__ == '__main__': model = whisper.load_model("base") result = model.transcribe("turkce.mp3") print(result["text"])
错误信息
C:\Users\root\AppData\Local\Microsoft\WindowsApps\python3.9.exe D:\PycharmProjects\SpeechToText\main.py None Traceback (most recent call last): File "D:\PycharmProjects\SpeechToText\main.py", line 1, in <module> import whisper as wp File "C:\Users\root\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\whisper.py", line 70, in <module> libc = ctypes.CDLL(libc_name) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\ctypes\__init__.py", line 364, in __init__ if '/' in name or '\\' in name: TypeError: argument of type 'NoneType' is not iterable Process finished with exit code 1
已尝试操作
pip uninstall whisper pip install git+https://github.com/openai/whisper.git
解决方案
Windows系统没有Linux下的libc库,对应的等效库是msvcrt.dll,可通过以下方式解决:
方法1:修改whisper源码适配Windows
- 找到whisper.py的安装路径(示例路径:
C:\Users\root\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\whisper.py) - 定位到第70行前后的代码块,替换为以下内容:
import platform # 针对Windows系统指定msvcrt.dll,其他系统保留原有逻辑 if platform.system() == "Windows": libc = ctypes.CDLL('msvcrt.dll') else: libc_name = ctypes.util.find_library('c') libc = ctypes.CDLL(libc_name)
方法2:在代码中提前指定库路径
无需修改源码,在导入whisper前手动加载Windows等效库:
import ctypes import os # 确保系统库路径被识别 os.environ['PATH'] += os.pathsep + 'C:\\Windows\\System32' # 提前加载msvcrt.dll ctypes.CDLL('msvcrt.dll') # 再导入whisper import whisper if __name__ == '__main__': model = whisper.load_model("base") result = model.transcribe("turkce.mp3") print(result["text"])
方法3:升级Python版本
Python 3.10及以上版本对Windows下ctypes.util.find_library的处理逻辑更完善,部分场景下可自动识别等效库,升级后可能直接解决问题。
内容的提问来源于stack exchange,提问作者Mustafa
相关产品推荐
相关产品推荐

