electronstudio / raylib-python-cffi

Python CFFI bindings for Raylib
http://electronstudio.github.io/raylib-python-cffi
Eclipse Public License 2.0
142 stars 29 forks source link

Runtime link errors after building on Raspberry Pi 3 #66

Closed sdillard closed 2 years ago

sdillard commented 2 years ago

I have an RPI3 and tried the default install and it was failing, so I built raylib from source and that is working fine (tests and examples pass). I checked that it shows in pkg-config, so all looks good. I tried installing this from pip (using Python 3.8) and got errors but after some cleaning, it installed. I was getting the error below, so I built the wheel from source and installed that and am getting the same error. My eventual goal is to run without X11 btw, but I have tried from booting to console and in terminal. Same error:

pi@raspberrypi:~/projects $ python3.8 test2.py 
Traceback (most recent call last):
  File "test2.py", line 1, in <module>
    from pyray import *
  File "/usr/local/lib/python3.8/site-packages/pyray/__init__.py", line 15, in <module>
    from raylib import rl, ffi
  File "/usr/local/lib/python3.8/site-packages/raylib/__init__.py", line 15, in <module>
    from ._raylib_cffi import ffi, lib as rl
ImportError: /usr/local/lib/python3.8/site-packages/raylib/_raylib_cffi.cpython-38-arm-linux-gnueabihf.so: undefined symbol: eglGetProcAddress

the test is really simple:

from pyray import *

init_window(200, 200, "Window Title")
begin_drawing()
clear_background(WHITE)
draw_text("Hello world", 20, 20, 20, VIOLET)
end_drawing()

I am 99.9% sure I have installed all dependencies and I do have cffi and inflection showing up - here's my pip list output:

pi@raspberrypi:~/projects $ pip3.8 list
Package    Version     
---------- ------------
cffi       1.15.0      
inflection 0.5.1       
pip        19.2.3      
pycparser  2.21        
raylib     4.1.0.0.dev1
setuptools 41.2.0      
wheel      0.37.1 

I am stuck. Any pointers? Thanks in advance

electronstudio commented 2 years ago

Seems like it hasn't correctly linked against OpenGL. But it ought to give that error at build time, not run time. Make sure it's using the wheel you built and not some other one. I do fortunately have a RPI3 so I can test it... but it works fine for me. Maybe ask on Raylib Discord.


pi@raspberrypi:~ $ python3 --version
Python 3.9.2

pi@raspberrypi:~ $ uname -a
Linux raspberrypi 5.10.63-v7+ #1488 SMP Thu Nov 18 16:14:44 GMT 2021 armv7l GNU/Linux

pi@raspberrypi:~ $ pip3 install raylib
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting raylib
  Downloading raylib-4.0.0.6.tar.gz (61 kB)
     |████████████████████████████████| 61 kB 92 kB/s 
Requirement already satisfied: cffi>=1.14.6 in ./.local/lib/python3.9/site-packages (from raylib) (1.15.0)
Requirement already satisfied: inflection in ./.local/lib/python3.9/site-packages (from raylib) (0.5.1)
Requirement already satisfied: pycparser in ./.local/lib/python3.9/site-packages (from cffi>=1.14.6->raylib) (2.21)
Building wheels for collected packages: raylib
  Building wheel for raylib (setup.py) ... done
  Created wheel for raylib: filename=raylib-4.0.0.6-cp39-cp39-linux_armv7l.whl size=1933676 sha256=225b1e6727631d481f8bb6c457cd0d169598c95c39b46d061e0ec343ad04cbc8
  Stored in directory: /home/pi/.cache/pip/wheels/15/9c/0f/f60a7e1275a3b946996840e7962ec62d434e3807277f308310
Successfully built raylib
Installing collected packages: raylib
Successfully installed raylib-4.0.0.6

pi@raspberrypi:~ $ python3 test.py
RAYLIB STATIC 4.0.0.6 LOADED
INFO: Initializing raylib 4.0
INFO: DISPLAY: Device initialized successfully
INFO:     > Display size: 3440 x 1440
INFO:     > Screen size:  800 x 450
INFO:     > Render size:  800 x 450
INFO:     > Viewport offsets: 0, 0
INFO: GLAD: OpenGL extensions loaded successfully
INFO: GL: Supported extensions count: 200
INFO: GL: OpenGL device information:
INFO:     > Vendor:   Mesa/X.org
INFO:     > Renderer: llvmpipe (LLVM 11.0.1, 128 bits)
INFO:     > Version:  4.5 (Core Profile) Mesa 20.3.5
INFO:     > GLSL:     4.50
INFO: GL: DXT compressed textures supported
INFO: GL: ETC2/EAC compressed textures supported
INFO: TEXTURE: [ID 1] Texture loaded successfully (1x1 | R8G8B8A8 | 1 mipmaps)
INFO: TEXTURE: [ID 1] Default texture loaded successfully
INFO: SHADER: [ID 1] Vertex shader compiled successfully
INFO: SHADER: [ID 2] Fragment shader compiled successfully
INFO: SHADER: [ID 3] Program shader loaded successfully
INFO: SHADER: [ID 3] Default shader loaded successfully
INFO: RLGL: Render batch vertex buffers loaded successfully in RAM (CPU)
INFO: RLGL: Render batch vertex buffers loaded successfully in VRAM (GPU)
INFO: RLGL: Default OpenGL state initialized successfully
INFO: TEXTURE: [ID 2] Texture loaded successfully (128x128 | GRAY_ALPHA | 1 mipmaps)
INFO: FONT: Default font loaded successfully (224 glyphs)
INFO: TEXTURE: [ID 2] Unloaded texture data from VRAM (GPU)
INFO: SHADER: [ID 3] Default shader unloaded successfully
INFO: TEXTURE: [ID 1] Default texture unloaded successfully
INFO: Window closed successfully
electronstudio commented 2 years ago

I do recall that Raylib has issues with Pi support, and I think only works on certain versions of Raspbian because Raspbian keeps changing how the OpenGL drivers work.

sdillard commented 2 years ago

Thanks for the reply. Doing a clean build of my pi and moving to Buster. Will report back and close/update this soon. I did notice that my python was not able to use the wheel and ran the setup.py, so I'll make sure I have wheel support working first.

sdillard commented 2 years ago

I'm closing this as I worked around it, but I could not get this working. I did a clean install with Buster on raspian lite, installed dependencies, built raylib, got pkg-config working (that seemed more difficult than expected), and raylib installed, and pip installs fine, but it gave cffi errors whenever I try to run. I then installed raylib_dynamic and it works just fine, so I'm going with it. I do think complete steps on a pi would be useful to document, but maybe it just isn't that common to do what I'm doing. Thanks again for the reply.

electronstudio commented 2 years ago

We did actually have some tutorial for Pi in the docs, written by the last person who got it working. But Pi changed and those steps didn’t work any more! I don’t have time right now, especially since it works for me, but when/if I do I will try a from scratch install and see if I can reproduce.

sometimes people on the discord have more free time, still might be worth asking there.

electronstudio commented 2 years ago

Everything should now work on RPI3 (and 4 I presume) Bullseye with Raylib X11 (PLATFORM_DESKTOP) and with Raylib PLATFORM_DRM.

Older OSes and Raylib PLATFORM_RPI probably wont work.

See https://github.com/electronstudio/raylib-python-cffi/blob/master/RPI.rst

Please reopen if not working.