0

I wouldn't call myself a programmer and am unfamiliar with Mac and Linux, so any links or pointers to additional background would help greatly. I've started with the most basic pygame I could google, (from https://realpython.com/pygame-a-primer/). The test.py and test.app runs on my VM but not on anyone else's real Macs.


test.py file

import pygame

    pygame.init()
    screen = pygame.display.set_mode((400, 300))
    done = False

    while not done:
            for event in pygame.event.get():
                    if event.type == pygame.QUIT:
                            done = True

            pygame.display.flip()

setup.py file

from setuptools import setup

APP = ['test.py']
DATA_FILES = []
OPTIONS = {}

setup(
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)

command to create the test.app

$ python3 setup.py py2app


The test.app runs fine on the VM, but whenever the test.app runs on a real Mac (tested 2, one ran on Catalina ver???) this error message appears:


Traceback (most recent call last):
  File "/Applications/test.app/Contents/Resources/__boot__.py", line 101, in <module>
    _run()
  File "/Applications/test.app/Contents/Resources/__boot__.py", line 84, in _run
    exec(compile(source, path, "exec"), globals(), globals())
  File "/Applications/test.app/Contents/Resources/test.py", line 1, in <module>
    import pygame
  File "pygame/__init__.pyc", line 120, in <module>
  File "pygame/base.pyc", line 14, in <module>
  File "pygame/base.pyc", line 10, in __load
  File "imp.pyc", line 343, in load_dynamic
ImportError: dlopen(/Applications/test.app/Contents/Resources/lib/python3.7/lib-dynload/pygame/base.so, 2): Library not loaded: @loader_path/.dylibs/libSDL-1.2.0.dylib
  Referenced from: /Applications/test.app/Contents/Resources/lib/python3.7/lib-dynload/pygame/base.so
  Reason: image not found
2020-05-02 11:27:50.309 test[931:15836] test Error

----------------------------
Working environment: VirtualBox 6.1, macOS Sierra (Version 10.12) with the following:

$ pip list

Package     Version
----------- ----------
altgraph    0.17
certifi     2020.4.5.1
macholib    1.14
modulegraph 0.18
pip         20.1
py2app      0.21
pygame      1.9.6
setuptools  39.0.1
wheel       0.34.2

$ brew list --versions

freetype 2.10.1
gdbm 1.18.1
jpeg 9d
libmikmod 3.3.11.1
libogg 1.3.4
libpng 1.6.37
libtiff 4.1.0
libvorbis 1.3.6
openssl@1.1 1.1.1g
pkg-config 0.29.2_3
python 3.7.7
readline 8.0.4
sdl 1.2.15_1
sdl2 2.0.12_1
sdl_image 1.2.12_7
sdl_mixer 1.2.12_3
sdl_ttf 2.0.11_1
sqlite 3.31.1
webp 1.1.0
xz 5.2.5

Any ideas or pointers would be greatly appreciated. The actual program is an OhHell card game which supports Windows clients (via pyinstaller), but I'm also trying to support a Mac client to play with my friends on a Mac. Similar to the test.py and test.app (ohhell.py and ohhell.app) runs on the VM Mac but same issue/error occurs with real macs. I've just included the simplest code snippet that I was able to google that reproduced the exact error message.

-john

  • I guess a few more useful comments: 1) /test.app/Contents/Frameworks/libSDL-1.2.0.dylib does exist 2) the libSDL-1.2.0.dylib did not exist on the real mac that it failed (outside the test.app package itself) 3) I tried including that dylib in the setup_test.py DATA_FILES – John Liu May 04 '20 at 22:35
  • I updated to the latest setuptools (setuptools-46.1.3), but still get the with same message. – John Liu May 05 '20 at 18:51
  • It appears the application runs on a real Mac provided the following .dylib files are installed separately (was installed and removed via brew). It cannot reference them on the App Package Contents: sdl 1.2.15_1 (base.so error), sdl_mixer 1.2.12_3 (mixer.so error), sdl_ttf 2.0.11_1 (font.so error) – John Liu May 16 '20 at 17:59

1 Answers1

0

Workaround Solution: Linking to a dynamic library on a Mac with full path and What path does @loader_path resolve to?. Using the '$ install_name_tool -change "@loader_path/.dylibs/libSDL-1.2.0.dylib" "/Applications/test.app/Contents/Frameworks/libSDL-1.2.0.dylib" base.so' resolved the Library not loaded: loader_path/.dylibs/libSDL-1.2.0.dylib errors. I assume this hard codes the path, but with my friends it's fine to tell them to make sure it resides in the /Applications folder.

However a secondary problem came up, 'pygame.error: File is not a Windows BMP file'. I used py2app, so the pygame delete and reinstall threads didn't seem like a feasible solution (pygame unnecesary w/py2app), so switching the images to uncompressed bitmap (256 colors) worked.

For those curious, I did try Pyinstaller for Mac but that presented a whole new set of problems.