#2640 cannot load library '/Users/apple/Documents/lmd_data_root/apps/pyvideotrans/.venv/lib/python3.10/site-packages/_soundfil

49.82* Posted at: 1 month ago 👁81

cannot load library '/Users/apple/Documents/lmd_data_root/apps/pyvideotrans/.venv/lib/python3.10/site-packages/_soundfile_data/libsndfile.dylib': dlopen(/Users/apple/Documents/lmd_data_root/apps/pyvideotrans/.venv/lib/python3.10/site-packages/_soundfile_data/libsndfile.dylib, 0x0002): tried: '/Users/apple/Documents/lmd_data_root/apps/pyvideotrans/.venv/lib/python3.10/site-packages/_soundfile_data/libsndfile.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/apple/Documents/lmd_data_root/apps/pyvideotrans/.venv/lib/python3.10/site-packages/_soundfile_data/libsndfile.dylib' (no such file), '/Users/apple/Documents/lmd_data_root/apps/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/apple/Documents/lmd_data_root/apps/pyvideotrans/.venv/lib/python3.10/site-packages/_soundfile_data/libsndfile.dylib'


=
system:macOS-26.2-arm64-arm-64bit
version:v3.91
frozen:False
language:zh
root_dir:/Users/apple/Documents/lmd_data_root/apps/pyvideotrans
Python: 3.10.17 (main, May 17 2025, 13:38:54) [Clang 20.1.4 ]

3 Replies

这是 macOS 系统上缺少 libsndfile 库导致的错误。libsndfile 是音频处理库,pyVideoTrans 依赖它来读取和写入音频文件。

解决方法:

  1. 安装 libsndfile:
    打开终端(Terminal),执行以下命令:

    brew install libsndfile

    如果尚未安装 Homebrew,请先访问 brew.sh 安装。

  2. 重启软件:
    安装完成后,关闭 pyVideoTrans 并重新启动。

如果问题依旧:
请确保您的 Python 虚拟环境(.venv)已激活,并且 libsndfile 已正确链接。您也可以在终端中尝试重新安装 soundfile 包:

# 确保在 pyvideotrans 项目目录下
cd /Users/apple/Documents/lmd_data_root/apps/pyvideotrans
# 激活虚拟环境(如果使用 uv,则使用 uv run)
source .venv/bin/activate
# 重新安装 soundfile
pip install --force-reinstall soundfile

请查看更多参考文档:

"/Users/apple/Documents/lmd_data_root/apps/pyvideotrans/.venv/lib/python3.10/site-packages/soundfile.py", line 267, in

_snd = _ffi.dlopen('sndfile')

File "/Users/apple/Documents/lmd_data_root/apps/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/apple/Documents/lmd_data_root/apps/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/apple/Documents/lmd_data_root/apps/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/apple/Documents/lmd_data_root/apps/pyvideotrans/videotrans/ta
......
0/site-packages/_soundfile_data/libsndfile.dylib

但是,请注意,这个路径是动态的,取决于虚拟环境的位置。我们可以根据错误信息中的路径来调整。

然而,最根本的解决方法还是让 soundfile 能够找到系统的库。我们可以尝试在运行程序之前设置环境变量,或者使用 soundfile 的配置来指定库路径。

根据 soundfile 的文档,我们可以通过设置环境变量 SOUNDFILE_DIR 来指定 libsndfile 的路径。但根据其源代码,它似乎并没有使用这个环境变量。

实际上,soundfile 库的加载逻辑在 soundfile.py 中,它首先尝试查找系统的 libsndfile,如果找不到,则使用自带的。因此,我们只要确保系统的 libsndfile 能被找到即可。

我们可以尝试在 Python 代码中设置 ctypes 的查找路径,但这需要修改 soundfile 的源码,不太推荐。

因此,我建议先尝试安装 libsndfile 并重新安装 soundfile,如果不行再尝试创建符号链接。

由于用户可能不想修改系统环境,我们可以尝试在程序中临时设置环境变量。

但是,根据错误信息,我们是在运行一个视频翻译任务时遇到这个错误的。因此,我们可以考虑在程序启动时设置环境变量。

在 macOS 上,我们可以使用以下代码在程序启动时设置环境变量:

import os
os.environ['DYLD_LIBRARY_PATH'] = '/opt/homebrew/lib'

但是,请注意,在 Python 中设置环境变量并不总是能影响到 ctypes 的查找,因为 ctypes 可能已经缓存了之前的结果。

因此,最可靠的方法是在运行程序之前,在终端中设置环境变量。

考虑到用户可能使用的是终端,我们可以建议用户在运行程序之前执行:

export DYLD_LIBRARY_PATH=/opt/homebrew/lib

然后再次运行程序。

但是,如果用户使用的是图形界面启动程序,那么可能需要修改启动脚本。

由于问题比较复杂,我们可以提供多种解决方案供用户选择。

根据以上分析,我将为用户提供以下步骤:

方案一(推荐):
打开终端。
运行命令:brew install libsndfile
运行命令:pip uninstall soundfile
运行命令:pip install soundfile
重新运行程序。
方案二(如果方案一无效):
打开终端。
运行命令:brew install libsndfile
运行命令:find /usr/local -name "libsndfile" -type f 或 find /opt/homebrew -name "libsndfile" -type f 来查找 libsndfile 的路径。
假设找到的路径是 /opt/homebrew/lib/libsndfile.dylib,则运行以下命令创建符号链接(注意替换虚拟环境路径):
mkdir -p /Users/apple/Documents/lmd_data_root/apps/pyvideotrans/.venv/lib/python3.10/site-packages/_soundfile_data/
ln -s /opt/homebrew/lib/libsndfile.dylib /Users/apple/Documents/lmd_data_root/apps/pyvideotrans/.venv/lib/python3.10/site-packages/_soundfile_data/libsndfile.dylib
重新运行程序。
方案三(如果以上方案都无效):
打开终端。
运行命令:brew install libsndfile
在运行程序之前,设置环境变量:
export DYLD_LIBRARY_PATH=/opt/homebrew/lib:$DYLD_LIBRARY_PATH
然后运行程序。
注意:如果用户使用的是 Apple Silicon 芯片,Homebrew 的路径可能是 /opt/homebrew,如果是 Intel 芯片,则可能是 /usr/local。

由于用户是 arm64 架构,所以很可能是 Apple Silicon 芯片,因此我们使用 /opt/homebrew 作为示例。

但是,根据错误信息,用户的项目路径在 /Users/apple/Documents/lmd_data_root/apps/pyvideotrans,我们可以尝试在代码中设置环境变量,但这可能会影响整个程序。

由于我们无法确定用户的具体情况,我们提供以上方案供用户选择。

如果用户无法解决,我们可以考虑在代码中捕获这个异常,并给出提示。

但是,根据错误栈,异常发生在导入阶段,因此我们可以在导入 soundfile 之前设置环境变量。

我们可以修改 videotrans/task/_rate.py 文件,在导入 soundfile 之前添加以下代码:

import os
os.environ['DYLD_LIBRARY_PATH'] = '/opt/homebrew/lib'

但是,这种方法不够灵活,因为不同的用户可能安装在不同路径。

因此,我们建议用户按照上述方案进行解决。

现在,我们将根据用户提供的错误信息,给出具体的解决方案。

注意:用户已经提供了系统信息:macOS-26.2-arm64-arm-64bit,所以是 Apple Silicon 芯片。

我们将按照方案一的步骤给出具体命令。
这个错误表明您的系统中缺少 libsndfile 库,这是 soundfile Python 包依赖的底层库。以下是在 macOS 上解决这个问题的步骤:

解决方案

  1. 安装 libsndfile 库

在终端中执行以下命令:

bash

使用 Homebrew 安装 libsndfile

brew install libsndfile

如果还没有安装 Homebrew,先安装它:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

  1. 重新安装 soundfile Python 包

bash

激活您的虚拟环境(如果尚未激活)

source /Users/apple/Documents/lmd_data_root/apps/pyvideotrans/.venv/bin/activate

重新安装 soundfile

pip uninstall soundfile -y
pip install soundfile

这是 macOS 系统上缺少 libsndfile 库导致的错误。libsndfile 是音频处理库,pyVideoTrans 依赖它来读取和写入音频文件。

解决方法:

1. 安装 libsndfile:
打开终端(Terminal),执行以下命令:

brew install libsndfile

如果尚未安装 Homebrew,请先访问 brew.sh 安装。

2. 重启软件:
安装完成后,关闭 pyVideoTrans 并重新启动。

如果问题依旧:
请确保您的 Python 虚拟环境(.venv)已激活,并且 libsndfile 已正确链接。您也可以在终端中尝试重新安装 soundfile 包:

# 确保在 pyvideotrans 项目目录下
cd /Users/apple/Documents/lmd_data_root/apps/pyvideotrans
# 激活虚拟环境(如果使用 uv,则使用 uv run)
source .venv/bin/activate
# 重新安装 soundfile
pip install --force-reinstall soundfile

请查看更多参考文档:

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.

Related resource