-
Notifications
You must be signed in to change notification settings - Fork 43
Open
Description
Hello!
I'm trying to freeze an app that has some functions which need torch and torchaudio. Unfortunately, I get the following error when running the app:
OSError: dlopen(***********/dist/TorchTest.app/Contents/Resources/lib/python3.9/torchaudio/lib/libtorchaudio.so, 0x0006): Library not loaded: '@rpath/libtorch.dylib'
Referenced from: '***********/dist/TorchTest.app/Contents/Resources/lib/python3.9/torchaudio/lib/libtorchaudio.so'
Reason: tried: '/usr/local/lib/libtorch.dylib' (no such file), '/usr/lib/libtorch.dylib' (no such file)
(I've edited out the full path ***********)
To simplify, I've tried to compile this snipped of code only (torchtest.py), but it returns the same error:
import torch
import torchaudio
import librosa
import onnxruntime
import resampy
print('Loading audio file...')
audio_array, sr = librosa.load('example_vad.wav', sr=16_000)
print('Loading silero model...')
# load the silero model
vad_model, utils = torch.hub.load(repo_or_dir='snakers4/silero-vad', model='silero_vad', force_reload=False,
onnx=True, trust_repo=True, verbose=False)
(get_speech_timestamps, _, read_audio, _, collect_chunks) = utils
# convert the audio_segment to a torch tensor
audio_segment_torch = torch.from_numpy(audio_array)
print('Running silero model...')
speech_timestamps = get_speech_timestamps(audio_segment_torch, vad_model,
sampling_rate=16_000,
window_size_samples=512,
speech_pad_ms=200,
threshold=0.5
)
print('Done!')
print(speech_timestamps)
And this is the setup.py I'm using when doing python setup.py py2app:
from setuptools import setup
import sys
sys.setrecursionlimit(10000)
APP = [{'script': 'torchtest.py'}]
DATA_FILES = ['example_vad.wav']
# all the frameworks compiled for M1
frameworks = [
# libffi from homebrew
'/opt/homebrew/Cellar/libffi/3.4.2/lib/libffi.8.dylib',
'/opt/homebrew/Cellar/libffi/3.4.2/lib/libffi.7.dylib',
'/opt/homebrew/Cellar/libffi/3.4.2/lib/libffi.dylib',
# trying to load from venv
#(files are copied in the Frameworks dir, but app doesn't look for them there I think
'venv/lib/python3.9/site-packages/torch/lib/libc10.dylib',
'venv/lib/python3.9/site-packages/torch/lib/libshm.dylib',
'venv/lib/python3.9/site-packages/torch/lib/libtorch_cpu.dylib',
'venv/lib/python3.9/site-packages/torch/lib/libtorch_global_deps.dylib',
'venv/lib/python3.9/site-packages/torch/lib/libtorch_python.dylib',
'venv/lib/python3.9/site-packages/torch/lib/libtorch.dylib'
]
OPTIONS = {
'frameworks': frameworks,
'includes': [],
'packages': ['cffi', 'librosa', 'torch', 'torchaudio', 'resampy', 'soundfile', '_soundfile'],
'excludes': ['PyInstaller', 'py2app'],
'plist': {
'LSUIElement': False,
'NSRequiresAquaSystemAppearance': False,
'CFBundleName': 'TorchTest',
'CFBundleDisplayName': 'TorchTest',
'CFBundleIdentifier': 'com.test.TorchTest',
'CFBundleGetInfoString': 'TorchTest',
'CFBundleVersion': '0.0.1',
'CFBundleShortVersionString': '0.0.1'
}
}
setup(
app=APP,
name ='TorchTest',
version = "{}".format(version.__version__),
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
I'm running py2app on Mac OS 12.6 (M1).
It seems that despite the dylibs are being copied when I include them in the frameworks list, they are not correctly referenced by ibtorchaudio.so.
Any ideas would be greatly appreciated!
Cheers
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels