libtcod / python-tcod

A high-performance Python port of libtcod. Includes the libtcodpy module for backwards compatibility with older projects.
BSD 2-Clause "Simplified" License
413 stars 36 forks source link

Mac OS 10.12.4 isn't happy with SDL in tdl #26

Closed athornton closed 7 years ago

athornton commented 7 years ago
adam@ixitxachitl:~$ mkvirtualenv -p $(which python3) tdl
Running virtualenv with interpreter /usr/local/bin/python3
Using base prefix '/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6'
New python executable in /Users/adam/Documents/src/Venvs/tdl/bin/python3.6
Also creating executable in /Users/adam/Documents/src/Venvs/tdl/bin/python
Installing setuptools, pip, wheel...done.
virtualenvwrapper.user_scripts creating /Users/adam/Documents/src/Venvs/tdl/bin/predeactivate
virtualenvwrapper.user_scripts creating /Users/adam/Documents/src/Venvs/tdl/bin/postdeactivate
virtualenvwrapper.user_scripts creating /Users/adam/Documents/src/Venvs/tdl/bin/preactivate
virtualenvwrapper.user_scripts creating /Users/adam/Documents/src/Venvs/tdl/bin/postactivate
virtualenvwrapper.user_scripts creating /Users/adam/Documents/src/Venvs/tdl/bin/get_env_details
(tdl) adam@ixitxachitl:~$ mkdir -p ~/Documents/src/tdl
(tdl) adam@ixitxachitl:~$ cd ~/Documents/src/tdl
(tdl) adam@ixitxachitl:~/Documents/src/tdl$ brew list sdl2
/usr/local/Cellar/sdl2/2.0.5/bin/sdl2-config
/usr/local/Cellar/sdl2/2.0.5/include/SDL2/ (70 files)
/usr/local/Cellar/sdl2/2.0.5/lib/libSDL2-2.0.0.dylib
/usr/local/Cellar/sdl2/2.0.5/lib/cmake/SDL2/sdl2-config.cmake
/usr/local/Cellar/sdl2/2.0.5/lib/pkgconfig/sdl2.pc
/usr/local/Cellar/sdl2/2.0.5/lib/ (4 other files)
/usr/local/Cellar/sdl2/2.0.5/share/aclocal/sdl2.m4
(tdl) adam@ixitxachitl:~/Documents/src/tdl$ pip install -U pip
Requirement already up-to-date: pip in /Users/adam/Documents/src/Venvs/tdl/lib/python3.6/site-packages
(tdl) adam@ixitxachitl:~/Documents/src/tdl$ pip install --no-cache-dir tdl
Collecting tdl
  Downloading tdl-3.0.1-py2.py3-none-any.whl
Collecting libtcod-cffi<3,>=2.3.0 (from tdl)
  Downloading libtcod_cffi-2.4.0-cp33-abi3-macosx_10_11_x86_64.whl (978kB)
    100% |################################| 983kB 1.7MB/s
Collecting cffi<2,>=1.8.1 (from libtcod-cffi<3,>=2.3.0->tdl)
  Downloading cffi-1.10.0-cp36-cp36m-macosx_10_6_intel.whl (227kB)
    100% |################################| 235kB 2.7MB/s
Collecting numpy<2,>=1.10 (from libtcod-cffi<3,>=2.3.0->tdl)
  Downloading numpy-1.12.1-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (4.4MB)
    100% |################################| 4.4MB 7.6MB/s
Collecting pycparser (from cffi<2,>=1.8.1->libtcod-cffi<3,>=2.3.0->tdl)
  Downloading pycparser-2.17.tar.gz (231kB)
    100% |################################| 235kB 4.5MB/s
Installing collected packages: pycparser, cffi, numpy, libtcod-cffi, tdl
  Running setup.py install for pycparser ... done
Successfully installed cffi-1.10.0 libtcod-cffi-2.4.0 numpy-1.12.1 pycparser-2.17 tdl-3.0.1
(tdl) adam@ixitxachitl:~/Documents/src/tdl$ cat > rl.py
#!/usr/bin/env python
import tdl

SCREEN_WIDTH = 80
SCREEN_HEIGHT = 24
LIMIT_FPS = 20

tdl.set_font('arial10x10.png', greyscale=True, altLayout=True)
console = tdl.init(SCREEN_WIDTH, SCREEN_HEIGHT, title="Crap Roguelike",
                   fullscreen=False)
while not tdl.event.is_window_closed():
    console.draw_char(1, 1, '@', bg=None, fg=(255, 255, 255))
    tdl.flush()
(tdl) adam@ixitxachitl:~/Documents/src/tdl$ python rl.py
Traceback (most recent call last):
  File "rl.py", line 2, in <module>
    import tdl
  File "/Users/adam/Documents/src/Venvs/tdl/lib/python3.6/site-packages/tdl/__init__.py", line 76, in <module>
    from tcod import ffi as _ffi
  File "/Users/adam/Documents/src/Venvs/tdl/lib/python3.6/site-packages/tcod/__init__.py", line 20, in <module>
    from tcod.libtcodpy import *
  File "/Users/adam/Documents/src/Venvs/tdl/lib/python3.6/site-packages/tcod/libtcodpy.py", line 10, in <module>
    from tcod.libtcod import *
  File "/Users/adam/Documents/src/Venvs/tdl/lib/python3.6/site-packages/tcod/libtcod.py", line 21, in <module>
    _ctypes.CDLL(_os.path.join(__path__[0], 'SDL2.framework/Versions/A/SDL2'))
  File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ctypes/__init__.py", line 348, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(/Users/adam/Documents/src/Venvs/tdl/lib/python3.6/site-packages/tcod/SDL2.framework/Versions/A/SDL2, 6): no suitable image found.  Did find:
    /Users/adam/Documents/src/Venvs/tdl/lib/python3.6/site-packages/tcod/SDL2.framework/Versions/A/SDL2: code signature invalid for '/Users/adam/Documents/src/Venvs/tdl/lib/python3.6/site-packages/tcod/SDL2.framework/Versions/A/SDL2'

    /Users/adam/Documents/src/Venvs/tdl/lib/python3.6/site-packages/tcod/SDL2.framework/Versions/A/SDL2: code signature invalid for '/Users/adam/Documents/src/Venvs/tdl/lib/python3.6/site-packages/tcod/SDL2.framework/Versions/A/SDL2'

(tdl) adam@ixitxachitl:~/Documents/src/tdl$ # OK, so I can sign it....
(tdl) adam@ixitxachitl:~/Documents/src/tdl$ codesign -f -s - /Users/adam/Documents/src/Venvs/tdl/lib/python3.6/site-packages/tcod/SDL2.framework/Versions/A/SDL2
/Users/adam/Documents/src/Venvs/tdl/lib/python3.6/site-packages/tcod/SDL2.framework/Versions/A/SDL2: replacing existing signature
(tdl) adam@ixitxachitl:~/Documents/src/tdl$ python rl.py
Traceback (most recent call last):
  File "rl.py", line 2, in <module>
    import tdl
  File "/Users/adam/Documents/src/Venvs/tdl/lib/python3.6/site-packages/tdl/__init__.py", line 76, in <module>
    from tcod import ffi as _ffi
  File "/Users/adam/Documents/src/Venvs/tdl/lib/python3.6/site-packages/tcod/__init__.py", line 20, in <module>
    from tcod.libtcodpy import *
  File "/Users/adam/Documents/src/Venvs/tdl/lib/python3.6/site-packages/tcod/libtcodpy.py", line 10, in <module>
    from tcod.libtcod import *
  File "/Users/adam/Documents/src/Venvs/tdl/lib/python3.6/site-packages/tcod/libtcod.py", line 88, in <module>
    from tcod._libtcod import lib, ffi
ImportError: dlopen(/Users/adam/Documents/src/Venvs/tdl/lib/python3.6/site-packages/tcod/_libtcod.abi3.so, 2): Library not loaded: @rpath/libomp.dylib
  Referenced from: /Users/adam/Documents/src/Venvs/tdl/lib/python3.6/site-packages/tcod/_libtcod.abi3.so
  Reason: image not found
HexDecimal commented 7 years ago

I might have added a regression trying to resolve this issue: https://github.com/HexDecimal/libtcod-cffi/issues/17. In libtcod-cffi v2.2.1 I tried to force load the SDL library which I think is causing this error.

I've created a patch release of libtcod-cffi v2.4.1 which removes the hack and bundles the dylibs properly. This fixes the missing libomp.dylib file, and it might fix the code signature issue. I'd need to hear from you to know.

athornton commented 7 years ago

It does indeed allow tdl to load, although I still have to codesign -f -s - /Users/adam/Documents/src/Venvs/tdl/lib/python3.6/site-packages/tcod/.dylibs/SDL2 . In any case, though, this lets me develop using tdl without needing to spin up a VM, so it's a reasonable fix for my purposes.

You might want to document needing to sign SDL, though, because it took a bit of Googling for me to figure out the first time that that was part of what was wrong.

HexDecimal commented 7 years ago

I've released libtcod-cffi v2.4.3 which replaces SDL2's signature before deployment. Every tool I have says the issue is fixed but I was never able to reproduce your error exactly.

If you can verify that the new version works out of the box then I can close this issue.

athornton commented 7 years ago

The new version works out of the box. Please close the issue. Thank you!