Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS - pysdl2-dll is installed as source-only #278

Closed
C0rn3j opened this issue Dec 17, 2024 · 5 comments
Closed

macOS - pysdl2-dll is installed as source-only #278

C0rn3j opened this issue Dec 17, 2024 · 5 comments

Comments

@C0rn3j
Copy link

C0rn3j commented Dec 17, 2024

UserWarning: pysdl2-dll is installed as source-only, meaning that it does not contain any binaries and will be ignored by PySDL2.\

I am attempting to use the pysdl2-dll library as per docs, but it seems like there are no prebuilt binaries, or I am installing it wrong, or more likely, I am shooting myself in the foot with pyinstaller.

I am trying to port Tauon to macOS in this PR branch - build logs with debug available in the CI jobs

It is built in the macos-latest GitHub runner, which to my understanding should have the prebuilt libraries from pysdl2-dll available, as it is new enough.

The CI job - https://github.com/Taiko2k/Tauon/pull/1348/files - installs both pysdl2-dll and PySDL2, and I tried to add "pysdl2-dll" as a hidden import to pyinstaller for good measure, but it still persists.

Mounting the final DMG and executing the volume gets me the warning above, I seem to need system SDL to get it working still.

Which files exactly does pysdl2-dll expect to find that would count as prebuilt?

@a-hurst
Copy link
Member

a-hurst commented Dec 17, 2024

Hi @C0rn3j!

Have never tried using pysdl2-dll with pyinstaller before, but if it doesn't currently work I'd certainly like to fix that! According to your CI logs in the "install python dependencies" step it looks like pip is fetching the wheel with the correct binaries rather than the sdist (pysdl2_dll-2.30.10-py2.py3-none-macosx_10_11_universal2.whl) so I'm not entirely sure what's going on to make it think otherwise.

In the meantime as a hacky workaround, you could just extract the .framework files directly from the wheel (since it's just a .zip file in disguise), include them in your project, and then set PYSDL2_DLL_PATH manually using os.environ.

Screen Shot 2024-12-17 at 1 18 17 PM

Can you send me a link to the built DMG? I can take a look and see if there's anything obvious on my end!

@C0rn3j
Copy link
Author

C0rn3j commented Dec 17, 2024

Can you send me a link to the built DMG?

Any of the succeeding CI jobs have a DMG in the summary https://github.com/C0rn3j/Tauon/actions/workflows/build_macOS.yaml

For example this one - https://github.com/C0rn3j/Tauon/actions/runs/12376535920 -> dl

@a-hurst
Copy link
Member

a-hurst commented Dec 17, 2024

Ah, just read up a bit more on pyinstaller and understand why pysdl2-dll doesn't work: basically it converts all the .py files to bytecode and bundles it all in a single binary, but pysdl2-dll works by a) bundling the platform-specific SDL2 binaries in a folder with the package source in the site-packages folder and b) setting the PYSDL2_DLL_PATH environment variable to point to that folder (relative to the packages __init__.py file) so pysdl2-dll will load them from that location. Pyinstaller breaks the file/folder structure, and thus breaks the functionality.

Maybe there's a way to modify pysdl2-dll to work with Pyinstaller somehow, but since the app-building process seems to bundle all the dylibs into the app's Contents/Frameworks folder anyway your easiest option would be to add a step in the bundling process to copy the frameworks from the folder in site-packages (./.venv/lib/python3.13/site-packages/sdl2dll/dll on your CI runner) into the app's Contents/Frameworks and then set PYSDL2_DLL_PATH to point to that folder somewhere the Tauon source when building a macOS app bundle.

@C0rn3j
Copy link
Author

C0rn3j commented Dec 19, 2024

pyinstaller changes parts of paths with a . with __dot__

https://github.com/pyinstaller/pyinstaller/blob/cad97cf681fc4ee9e0e0615ba2adc2d1c6726382/PyInstaller/building/osx.py#L28-L30

Interestingly enough it still creates a . directory too anyway, it's just empty:

dist/TauonMusicBox.app/Contents/Frameworks/sdl2dll/dll/SDL2_image.framework
dist/TauonMusicBox.app/Contents/Frameworks/sdl2dll/dll/SDL2_image__dot__framework
dist/TauonMusicBox.app/Contents/Frameworks/sdl2dll/dll/SDL2_image__dot__framework/Versions
dist/TauonMusicBox.app/Contents/Frameworks/sdl2dll/dll/SDL2_image__dot__framework/Versions/A
dist/TauonMusicBox.app/Contents/Frameworks/sdl2dll/dll/SDL2_image__dot__framework/Versions/A/Frameworks
dist/TauonMusicBox.app/Contents/Frameworks/sdl2dll/dll/SDL2_image__dot__framework/Versions/A/Frameworks/webp.framework
dist/TauonMusicBox.app/Contents/Frameworks/sdl2dll/dll/SDL2_image__dot__framework/Versions/A/Frameworks/webp.framework/Resources
dist/TauonMusicBox.app/Contents/Frameworks/sdl2dll/dll/SDL2_image__dot__framework/Versions/A/Frameworks/webp.framework/Versions
dist/TauonMusicBox.app/Contents/Frameworks/sdl2dll/dll/SDL2_image__dot__framework/Versions/A/Frameworks/webp.framework/Versions/A
dist/TauonMusicBox.app/Contents/Frameworks/sdl2dll/dll/SDL2_image__dot__framework/Versions/A/Frameworks/webp.framework/Versions/A/_CodeSignature
dist/TauonMusicBox.app/Contents/Frameworks/sdl2dll/dll/SDL2_image__dot__framework/Versions/A/Frameworks/webp.framework/Versions/A/_CodeSignature/CodeResources
dist/TauonMusicBox.app/Contents/Frameworks/sdl2dll/dll/SDL2_image__dot__framework/Versions/A/Frameworks/webp.framework/Versions/A/Resources
dist/TauonMusicBox.app/Contents/Frameworks/sdl2dll/dll/SDL2_image__dot__framework/Versions/A/Frameworks/webp.framework/Versions/A/Resources/Info.plist
dist/TauonMusicBox.app/Contents/Frameworks/sdl2dll/dll/SDL2_image__dot__framework/Versions/A/Frameworks/webp.framework/Versions/A/webp
dist/TauonMusicBox.app/Contents/Frameworks/sdl2dll/dll/SDL2_image__dot__framework/Versions/A/Frameworks/webp.framework/Versions/Current
dist/TauonMusicBox.app/Contents/Frameworks/sdl2dll/dll/SDL2_image__dot__framework/Versions/A/Frameworks/webp.framework/webp
dist/TauonMusicBox.app/Contents/Frameworks/sdl2dll/dll/SDL2_image__dot__framework/Versions/A/Frameworks/avif.framework
dist/TauonMusicBox.app/Contents/Frameworks/sdl2dll/dll/SDL2_image__dot__framework/Versions/A/Frameworks/avif.framework/Resources
dist/TauonMusicBox.app/Contents/Frameworks/sdl2dll/dll/SDL2_image__dot__framework/Versions/A/Frameworks/avif.framework/Versions
dist/TauonMusicBox.app/Contents/Frameworks/sdl2dll/dll/SDL2_image__dot__framework/Versions/A/Frameworks/avif.framework/Versions/A
dist/TauonMusicBox.app/Contents/Frameworks/sdl2dll/dll/SDL2_image__dot__framework/Versions/A/Frameworks/avif.framework/Versions/A/_CodeSignature
dist/TauonMusicBox.app/Contents/Frameworks/sdl2dll/dll/SDL2_image__dot__framework/Versions/A/Frameworks/avif.framework/Versions/A/_CodeSignature/CodeResources
dist/TauonMusicBox.app/Contents/Frameworks/sdl2dll/dll/SDL2_image__dot__framework/Versions/A/Frameworks/avif.framework/Versions/A/Resources
dist/TauonMusicBox.app/Contents/Frameworks/sdl2dll/dll/SDL2_image__dot__framework/Versions/A/Frameworks/avif.framework/Versions/A/Resources/Info.plist
dist/TauonMusicBox.app/Contents/Frameworks/sdl2dll/dll/SDL2_image__dot__framework/Versions/A/Frameworks/avif.framework/Versions/A/avif
dist/TauonMusicBox.app/Contents/Frameworks/sdl2dll/dll/SDL2_image__dot__framework/Versions/A/Frameworks/avif.framework/Versions/Current
dist/TauonMusicBox.app/Contents/Frameworks/sdl2dll/dll/SDL2_image__dot__framework/Versions/A/Frameworks/avif.framework/avif

Someone with macOS (I do not have a Mac unfortunately, so I rely on testers) tried it, and it seems to at least detect sdl2dll, but fails anyway - could it be due to these __dot__ paths not being handled?

UserWarning: Using SDL2 binaries from pysdl2-dll 2.30.10
Traceback (most recent call last):
  File "sdl2/sdlimage.py", line 33, in <module>
  File "sdl2/dll.py", line 253, in __init__
RuntimeError: could not find any library for SDL2_image (PYSDL2_DLL_PATH: /Applications/TauonMusicBox.app/Contents/Frameworks/sdl2dll/dll)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "tauon/__main__.py", line 63, in <module>
  File "PyInstaller/loader/pyimod02_importers.py", line 384, in exec_module
  File "sdl2/sdlimage.py", line 37, in <module>
ImportError: could not find any library for SDL2_image (PYSDL2_DLL_PATH: /Applications/TauonMusicBox.app/Contents/Frameworks/sdl2dll/dll)
[PYI-84800:ERROR] Failed to execute script '__main__' due to unhandled exception: could not find any library for SDL2_image (PYSDL2_DLL_PATH: /Applications/TauonMusicBox.app/Contents/Frameworks/sdl2dll/dll)
[PYI-84800:ERROR] Traceback:
Traceback (most recent call last):
  File "sdl2/sdlimage.py", line 33, in <module>
  File "sdl2/dll.py", line 253, in __init__
RuntimeError: could not find any library for SDL2_image (PYSDL2_DLL_PATH: /Applications/TauonMusicBox.app/Contents/Frameworks/sdl2dll/dll)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "tauon/__main__.py", line 63, in <module>
  File "PyInstaller/loader/pyimod02_importers.py", line 384, in exec_module
  File "sdl2/sdlimage.py", line 37, in <module>
ImportError: could not find any library for SDL2_image (PYSDL2_DLL_PATH: /Applications/TauonMusicBox.app/Contents/Frameworks/sdl2dll/dll)

I am confused as to what should be done here if so...

EDIT: Actually that looks like a pyinstaller bug... ".framework bundle directories are allowed to have dot in name"
Reported here - pyinstaller/pyinstaller#8936

@C0rn3j
Copy link
Author

C0rn3j commented Dec 19, 2024

Thank you for your assistance, I got it working:

datas=[
	(".venv/lib/python3.13/site-packages/sdl2dll/dll", "sdl2dll/dll"),
]

It did require one upstream fix from pyinstaller for macOS (as per the linked issue above), but with that one, it works on both Linux and macOS!

@C0rn3j C0rn3j closed this as completed Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants