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
410 stars 36 forks source link

Problem loading SDL2 on Mac OS #49

Closed mwv closed 6 years ago

mwv commented 6 years ago

Trying to install tcod for python 3 on mac os, but failing on import. I believe this is similar to the issue mentioned on reddit.

$ brew list sdl2
/usr/local/Cellar/sdl2/2.0.8/bin/sdl2-config
/usr/local/Cellar/sdl2/2.0.8/include/SDL2/ (72 files)
/usr/local/Cellar/sdl2/2.0.8/lib/libSDL2-2.0.0.dylib
/usr/local/Cellar/sdl2/2.0.8/lib/cmake/SDL2/sdl2-config.cmake
/usr/local/Cellar/sdl2/2.0.8/lib/pkgconfig/sdl2.pc
/usr/local/Cellar/sdl2/2.0.8/lib/ (4 other files)
/usr/local/Cellar/sdl2/2.0.8/share/aclocal/sdl2.m4

$ virtualenv -p $(which python3) tcod
Running virtualenv with interpreter /usr/local/bin/python3
Using base prefix '/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7'
/usr/local/lib/python3.7/site-packages/virtualenv.py:1041: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp
New python executable in /Users/maarten/tcod/bin/python3.7
Also creating executable in /Users/maarten/tcod/bin/python
Installing setuptools, pip, wheel...done.

$ source tcod/bin/activate

$ (tcod) pip3 install --no-cache-dir tcod
Collecting tcod
  Downloading https://files.pythonhosted.org/packages/21/ba/bde12211eb6911fa75a4eee418a9b2eaa91c3fa8fde9f935830255c7807e/tcod-6.0.5.tar.gz (687kB)
    100% |████████████████████████████████| 696kB 10.8MB/s
Collecting cffi<2,>=1.8.1 (from tcod)
  Downloading https://files.pythonhosted.org/packages/0b/ba/32835c9965d8a0090723e1d0b47373365525c4bd08c807b5efdc9fecbc99/cffi-1.11.5-cp37-cp37m-macosx_10_9_x86_64.whl (163kB)
    100% |████████████████████████████████| 163kB 11.7MB/s
Collecting numpy<2,>=1.10 (from tcod)
  Downloading https://files.pythonhosted.org/packages/f9/64/f47c172c2d2ee8907b5918ff7af7e52207f6bf4a57983e4474fcda728112/numpy-1.15.2-cp37-cp37m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (24.5MB)
    100% |████████████████████████████████| 24.5MB 17.0MB/s
Collecting pycparser (from cffi<2,>=1.8.1->tcod)
  Downloading https://files.pythonhosted.org/packages/68/9e/49196946aee219aead1290e00d1e7fdeab8567783e83e1b9ab5585e6206a/pycparser-2.19.tar.gz (158kB)
    100% |████████████████████████████████| 163kB 17.4MB/s
Installing collected packages: pycparser, cffi, numpy, tcod
  Running setup.py install for pycparser ... done
  Running setup.py install for tcod ... done
Successfully installed cffi-1.11.5 numpy-1.15.2 pycparser-2.19 tcod-6.0.5

$ (tcod) python3 -c "import tcod"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/maarten/tcod/lib/python3.7/site-packages/tcod/__init__.py", line 24, in <module>
    from tcod.libtcodpy import *
  File "/Users/maarten/tcod/lib/python3.7/site-packages/tcod/libtcodpy.py", line 14, in <module>
    from tcod.libtcod import *
  File "/Users/maarten/tcod/lib/python3.7/site-packages/tcod/libtcod.py", line 61, in <module>
    from tcod._libtcod import lib, ffi
ImportError: dlopen(/Users/maarten/tcod/lib/python3.7/site-packages/tcod/_libtcod.abi3.so, 2): Library not loaded: @rpath/SDL2.framework/Versions/A/SDL2
  Referenced from: /Users/maarten/tcod/lib/python3.7/site-packages/tcod/_libtcod.abi3.so
  Reason: image not found

$ (tcod) ls ~/tcod/lib/python3.7/site-packages/tcod/.dylibs
ls: /Users/maarten/tcod/lib/python3.7/site-packages/tcod/.dylibs: No such file or directory
HexDecimal commented 6 years ago

5 months ago I lost the ability to deploy wheels for versions of MacOS older than macosx_10_13_x86_64 due to SSL issues with those older versions of Python. On older or 32-bit MacOS tcod will try to build from source, and will end up skipping some post-packaging build steps designed to work around how MacOS links libraries.

MacOS is very strict on how it will dynamically link to libraries. If you want a usable workaround you'll need to rename the files from brew to match the path it asks for, or use the official SDL2 builds which tcod normally links to: https://www.libsdl.org/download-2.0.php

I'll see if I can make the older wheels again or have tcod link to the files installed by brew.

mwv commented 6 years ago

... or use the official SDL2 builds which tcod normally links to: https://www.libsdl.org/download-2.0.php

That did the trick. Thank you!

HexDecimal commented 6 years ago

I have macosx_10_6_intel wheels deploying again in tcod version 6.0.6. Be sure to say something if these don't work.

They bundle the SDL2 library so you should prefer them over the workaround.