#2074 OSError: cannot load library '/Users/justinfungcheuk/pyvideotrans/.venv/lib/python3.10/site-packages/_soundfile_data/lib

91.196* Posted at: 8 hours ago 👁11

Traceback (most recent call last):
File "/Users/justinfungcheuk/pyvideotrans/.venv/lib/python3.10/site-packages/soundfile.py", line 267, in

_snd = _ffi.dlopen('sndfile')

File "/Users/justinfungcheuk/pyvideotrans/.venv/lib/python3.10/site-packages/cffi/api.py", line 150, in dlopen

lib, function_cache = _make_ffi_library(self, name, flags)

File "/Users/justinfungcheuk/pyvideotrans/.venv/lib/python3.10/site-packages/cffi/api.py", line 834, in _make_ffi_library

backendlib = _load_backend_lib(backend, libname, flags)

File "/Users/justinfungcheuk/pyvideotrans/.venv/lib/python3.10/site-packages/cffi/api.py", line 829, in _load_backend_lib

raise OSError(msg)

OSError: ctypes.util.find_library() did not manage to locate a library called 'sndfile'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/justinfungcheuk/pyvideotrans/videotrans/mainwin/_main_win.py", line 75, in _set_Ui_Text

from videotrans import VERSION, recognition, tts

File "/Users/justinfungcheuk/pyvideotrans/videotrans/tts/__init__.py", line 26, in

from videotrans.tts._vits import VitsCNEN

File "/Users/justinfungcheuk/pyvideotrans/videotrans/tts/_vits.py", line 16, in

import soundfile as sf

File "/Users/justinfungcheuk/pyvideotrans/.venv/lib/python3.10/site-packages/soundfile.py", line 276, in

_snd = _ffi.dlopen(_os.path.join(

File "/Users/justinfungcheuk/pyvideotrans/.venv/lib/python3.10/site-packages/cffi/api.py", line 150, in dlopen

lib, function_cache = _make_ffi_library(self, name, flags)

File "/Users/justinfungcheuk/pyvideotrans/.venv/lib/python3.10/site-packages/cffi/api.py", line 834, in _make_ffi_library

backendlib = _load_backend_lib(backend, libname, flags)

File "/Users/justinfungcheuk/pyvideotrans/.venv/lib/python3.10/site-packages/cffi/api.py", line 829, in _load_backend_lib

raise OSError(msg)

OSError: cannot load library '/Users/justinfungcheuk/pyvideotrans/.venv/lib/python3.10/site-packages/_soundfile_data/libsndfile.dylib': dlopen(/Users/justinfungcheuk/pyvideotrans/.venv/lib/python3.10/site-packages/_soundfile_data/libsndfile.dylib, 0x0002): tried: '/Users/justinfungcheuk/pyvideotrans/.venv/lib/python3.10/site-packages/_soundfile_data/libsndfile.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/justinfungcheuk/pyvideotrans/.venv/lib/python3.10/site-packages/_soundfile_data/libsndfile.dylib' (no such file), '/Users/justinfungcheuk/pyvideotrans/.venv/lib/python3.10/site-packages/_soundfile_data/libsndfile.dylib' (no such file). Additionally, ctypes.util.find_library() did not manage to locate a library called '/Users/justinfungcheuk/pyvideotrans/.venv/lib/python3.10/site-packages/_soundfile_data/libsndfile.dylib'


=
system:macOS-14.6.1-arm64-i386-64bit
version:v3.90
frozen:False
language:zh
root_dir:/Users/justinfungcheuk/pyvideotrans
Python: 3.10.19 (main, Dec 9 2025, 19:17:38) [Clang 21.1.4 ]

3 Replies

您遇到的错误是由于缺少 libsndfile 库。这是在 macOS 上通过源码部署 pyVideoTrans 时的一个常见依赖问题。

核心解决方法:

  1. 打开终端
  2. 执行以下命令安装 libsndfile

    brew install libsndfile
  3. 安装完成后,重新启动 pyVideoTrans 软件即可。

原因说明:
软件内部的 soundfile 模块(用于音频文件读写)依赖于系统库 libsndfile。在 macOS 上,使用 Homebrew 包管理器可以方便地安装此依赖。此问题在【核心知识库】的“2.2 MacOS / Linux 用户 (源码部署)”部分已有提及。

如果安装 libsndfile 后问题依旧,请确保 Homebrew 已正确安装并更新(brew update),然后再次尝试。

仍然无法解决,显示一样的报错

问题依然存在,说明系统未能正确找到或链接到 libsndfile 库。这通常是因为 Python 的 soundfile 包安装的路径与系统库路径不匹配。请按以下步骤强制解决:

  1. 卸载并重新安装 soundfile
    在终端中,进入您的项目目录(/Users/justinfungcheuk/pyvideotrans),然后执行:

    uv run pip uninstall -y soundfile
    uv run pip install soundfile

    这会让 soundfile 尝试重新检测并链接到您刚通过 brew install 安装的 libsndfile

  2. 如果步骤1无效,尝试直接链接库文件
    首先,找到 libsndfile 被 Homebrew 安装的确切位置:

    brew --prefix libsndfile

    通常会输出类似 /opt/homebrew/opt/libsndfile 的路径。然后,创建一个符号链接到系统库目录:

    sudo ln -s $(brew --prefix libsndfile)/lib/libsndfile.dylib /usr/local/lib/libsndfile.dylib

    注意:如果 /usr/local/lib 不存在,可以先创建它:sudo mkdir -p /usr/local/lib

  3. 终极方案:使用 Conda 环境(如果 uv 环境问题持续)
    如果上述方法均失败,可能是当前 Python 环境与系统库的兼容性问题。您可以尝试使用 Conda 创建一个新环境,因为 Conda 能更好地管理非 Python 的 C 库依赖。

    # 安装 Miniconda (如果尚未安装)
    # 创建一个新环境并激活
    conda create -n videotrans python=3.10
    conda activate videotrans
    # 在 Conda 环境中安装 libsndfile 和 ffmpeg
    conda install -c conda-forge libsndfile ffmpeg
    # 然后在此环境中使用 pip 安装 pyVideoTrans 的其他依赖
    cd /Users/justinfungcheuk/pyvideotrans
    pip install -r requirements.txt
    # 最后运行
    python sp.py

请按顺序尝试上述步骤。如果问题依旧,请提供执行这些命令后的完整终端输出。

Post Your Reply
Open source and free maintenance is not easy. If this project is helpful to you, please consider making a small donation to help the project continue to maintain and update.

Donate: https://ko-fi.com/jianchang512

Trending Questions