Open octimot opened 1 year ago
Could this be related with the @rpath
issue mentioned here https://github.com/ronaldoussoren/py2app/issues/286 and technically fixed here https://github.com/ronaldoussoren/py2app/pull/315 ?
I'd love to help help with improvements, but just need a few pointers to know what I should be looking for.
To make sure that nothing weird is happening due to a packaged python installation, I've cleaned up all conda and homebrew python installs and reinstalled python 3.9.13 using the universal2 installer from pyhton.org.
Unfortunately, the @rpath error still persists.
I managed to manually change the @rpaths to @executable_paths like this:
First, I added the following code that collects all the libtorch related dylibs:
# add all the torch libs to the frameworks list
torch_libs = glob.glob(os.path.join(sys.exec_prefix, '**/libtorch*'), recursive=True)
frameworks += torch_libs
Then, after running python setup.py py2app
, I've manually changed the @rpaths using install_name_tool (from Terminal):
install_name_tool -change @rpath/libtorch.dylib @executable_path/../Resources/lib/python3.9/torch/lib/libtorch.dylib dist/TorchTest.app/Contents/Resources/lib/python3.9/torchaudio/lib/libtorchaudio.so
install_name_tool -change @rpath/libtorch_cpu.dylib @executable_path/../Resources/lib/python3.9/torch/lib/libtorch_cpu.dylib dist/TorchTest.app/Contents/Resources/lib/python3.9/torchaudio/lib/libtorchaudio.so
install_name_tool -change @rpath/libc10.dylib @executable_path/../Resources/lib/python3.9/torch/lib/libc10.dylib dist/TorchTest.app/Contents/Resources/lib/python3.9/torchaudio/lib/libtorchaudio.so
Since the signature on libtorchaudio.so is now invalidated, I needed to codesign it again:
codesign -f -s - dist/TorchTest.app/Contents/Resources/lib/python3.9/torchaudio/lib/libtorchaudio.so
Similarly, I found that _torchaudio.so also needs some path changes:
install_name_tool -change @rpath/libtorch.dylib @executable_path/../Resources/lib/python3.9/torch/lib/libtorch.dylib dist/TorchTest.app/Contents/Resources/lib/python3.9/torchaudio/_torchaudio.so
install_name_tool -change @rpath/libtorch_cpu.dylib @executable_path/../Resources/lib/python3.9/torch/lib/libtorch_cpu.dylib dist/TorchTest.app/Contents/Resources/lib/python3.9/torchaudio/_torchaudio.so
install_name_tool -change @rpath/libc10.dylib @executable_path/../Resources/lib/python3.9/torch/lib/libc10.dylib dist/TorchTest.app/Contents/Resources/lib/python3.9/torchaudio/_torchaudio.so
install_name_tool -change @rpath/libtorch_python.dylib @executable_path/../Resources/lib/python3.9/torch/lib/libtorch_python.dylib dist/TorchTest.app/Contents/Resources/lib/python3.9/torchaudio/_torchaudio.so
install_name_tool -change @rpath/libtorchaudio.so @executable_path/../Resources/lib/python3.9/torchaudio/lib/libtorchaudio.so dist/TorchTest.app/Contents/Resources/lib/python3.9/torchaudio/_torchaudio.so
codesign -f -s - dist/TorchTest.app/Contents/Resources/lib/python3.9/torchaudio/_torchaudio.so
BTW, to find out which paths need to be changed, I simply ran otool
on the affected files inside the bundle:
otool -L dist/TorchTest.app/Contents/Resources/lib/python3.9/torchaudio/lib/libtorchaudio.so
otool -L dist/TorchTest.app/Contents/Resources/lib/python3.9/torchaudio/_torchaudio.so
What would be the best approach to incorporate this into py2app?
This is because #315 has been reverted THis is false, the code has moved to https://github.com/ronaldoussoren/py2app/blob/master/src/py2app/apptemplate/setup.py#L23
I think I found the problem, PR coming up :)
Hi, @octimot Did you solve this problem? I have faced same issue in using py2app.
@fullstack-dev0727 try my fork (#504). Please respond whether it works, it needs tests.
@Tokarak Thanks for your message. I will test and let you know about the results.
Hi, @Tokarak What do I have to do exactly to resolve the issue?
@fullstack-dev0727 clone the fork and do pip install [path to repo]
. Then you can use python -m py2app
like usual.
Hi, @Tokarak Thanks for your reply. We can use py2app for arm64 M1 Mac mini?
{ "name": "main-x86_64", "target": "10.5", "cflags": "-g -arch x86_64 -Wl,-rpath,@executable_path/../Frameworks", "cc": "/usr/bin/clang", },
rpath can be used in only x84_64 machine?
@Tokarak I set rpath in arm64 manually by calling install_name_tool.
install_name_tool -add_rpath @executable_path/../Frameworks testapp
But app is stopped immediately. Please let me know the solution.
the issue I had, rpath was already set, butthe dylibs were not copied into the Frameworks folder (which should be in rpath already). Are there any dylibs in the Contents/Frameworks folder of your compiled app?
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:
(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:
And this is the setup.py I'm using when doing
python setup.py 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