electronstudio / raylib-python-cffi

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

Cant make it to work on raspberry pi4 #55

Closed TheBricktop closed 2 years ago

TheBricktop commented 2 years ago

Hello ive tried to install raylib_py through the pip build command but its not working correctly.

Im trying it on raspberry pi4 8gb and system is Twisteros 2.12 . Official raylib compiled without any problems whatsoever.

electronstudio commented 2 years ago

First, this is raylib-python-cffi and the pip package is named raylib not raylib_py so make sure you are installing the correct package.

We did used to work fine on Raspberry Pi but unfortunately I don't have one currently to test on, so the code has probably rotted. Can you post the output?

TheBricktop commented 2 years ago

yes sorry Ive meant : python3 -m pip install raylib Traceback (most recent call last): File "/home/pi/programs/depthAI_VIO/raylibTest.py", line 1, in <module> from pyray import * File "/home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/pyray/__init__.py", line 15, in <module> from raylib import rl, ffi File "/home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/raylib/__init__.py", line 15, in <module> from ._raylib_cffi import ffi, lib as rl ModuleNotFoundError: No module named 'raylib._raylib_cffi'

electronstudio commented 2 years ago

What is output from:

pip3 install --no-binary raylib --upgrade --force-reinstall raylib

?

If you could give me remote access to your raspberry pi it would probably help.

electronstudio commented 2 years ago

I have done some investigation. The default 'make install' raylib install doesn't include pkg-config, so you will definately have to do a cmake install: https://github.com/raysan5/raylib/wiki/Working-on-GNU-Linux#build-raylib-using-cmake

The next issue seems to be whether we are doing X11 graphics or 'native' raspberry pi graphics. Which are you using? There seem to be some hardcoded paths for the native graphics are no longer valid.

electronstudio commented 2 years ago

I found an old RPI3 and tried it with latest Rasbian OS. This no longer has the libraries that were hardcoded for native graphics before.

Raylib 4.0 in native mode won't compile on RPI3.

Raylib 4.0 in X11 mode compiles but it seems to be using the llvm-pipe driver which I guess is pretty slow and not going to be usable.

Does Raylib on RP4 work with X11 and proper fast drivers? If so I might just change the build to use X11. Raylib itself doesn't even work on current Rasbian RPI3 native so seems pointless to continue to support older versions where it did work.

TheBricktop commented 2 years ago

While i've used raylib ive compiled both versions the cli and x11 and cli worked correctly when ive used ctrl + alt + fn1 and run from console. The x11 worked with some examples but less performant and some shaders were not working correctly.

TheBricktop commented 2 years ago

pip3 install --no-binary raylib --upgrade --force-reinstall raylib
/home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/_distutils_hack/__init__.py:30: UserWarning: Setuptools is replacing distutils.
  warnings.warn("Setuptools is replacing distutils.")
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting raylib
  Using cached raylib-4.0.0.2.tar.gz (54 kB)
  Preparing metadata (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /home/pi/programs/depthAI_VIO/venv/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-3g4pioco/raylib_2a19d54fe9ba47bf8a96ad8c8a05ca2e/setup.py'"'"'; __file__='"'"'/tmp/pip-install-3g4pioco/raylib_2a19d54fe9ba47bf8a96ad8c8a05ca2e/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-9r0z16n_
       cwd: /tmp/pip-install-3g4pioco/raylib_2a19d54fe9ba47bf8a96ad8c8a05ca2e/
  Complete output (28 lines):
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/tmp/pip-install-3g4pioco/raylib_2a19d54fe9ba47bf8a96ad8c8a05ca2e/setup.py", line 42, in <module>
      cffi_modules=["raylib/build.py:ffibuilder"]
    File "/home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/setuptools/__init__.py", line 155, in setup
      return distutils.core.setup(**attrs)
    File "/home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/setuptools/_distutils/core.py", line 109, in setup
      _setup_distribution = dist = klass(attrs)
    File "/home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/setuptools/dist.py", line 463, in __init__
      for k, v in attrs.items()
    File "/home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/setuptools/_distutils/dist.py", line 293, in __init__
      self.finalize_options()
    File "/home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/setuptools/dist.py", line 837, in finalize_options
      ep(self)
    File "/home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/setuptools/dist.py", line 858, in _finalize_setup_keywords
      ep.load()(self, ep.name, value)
    File "/home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/cffi/setuptools_ext.py", line 219, in cffi_modules
      add_cffi_module(dist, cffi_module)
    File "/home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/cffi/setuptools_ext.py", line 49, in add_cffi_module
      execfile(build_file_name, mod_vars)
    File "/home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/cffi/setuptools_ext.py", line 25, in execfile
      exec(code, glob, glob)
    File "raylib/build.py", line 197, in <module>
      build_unix()
    File "raylib/build.py", line 101, in build_unix
      raise Exception("ERROR: raylib not found by pkg-config.  Please install pkg-config and Raylib.")
  Exception: ERROR: raylib not found by pkg-config.  Please install pkg-config and Raylib.
  not windows, trying Unix build
  ----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/90/1a/f54da612a1513225c78ffcda8cd17d23e9a7fdb9216af1197d062c4ed46a/raylib-4.0.0.2.tar.gz#sha256=abb326e39ef03ebbce2edd142ed3b342f40e0084d8eedaf7a13962131e46f8e8 (from https://pypi.org/simple/raylib/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
  Downloading raylib-4.0.0.1.tar.gz (54 kB)
     |████████████████████████████████| 54 kB 71 kB/s             
  Preparing metadata (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /home/pi/programs/depthAI_VIO/venv/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-3g4pioco/raylib_ef861a6d0c654a91be70f32a389ecca9/setup.py'"'"'; __file__='"'"'/tmp/pip-install-3g4pioco/raylib_ef861a6d0c654a91be70f32a389ecca9/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-2fg5fp0q
       cwd: /tmp/pip-install-3g4pioco/raylib_ef861a6d0c654a91be70f32a389ecca9/
  Complete output (28 lines):
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/tmp/pip-install-3g4pioco/raylib_ef861a6d0c654a91be70f32a389ecca9/setup.py", line 42, in <module>
      cffi_modules=["raylib/build.py:ffibuilder"]
    File "/home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/setuptools/__init__.py", line 155, in setup
      return distutils.core.setup(**attrs)
    File "/home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/setuptools/_distutils/core.py", line 109, in setup
      _setup_distribution = dist = klass(attrs)
    File "/home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/setuptools/dist.py", line 463, in __init__
      for k, v in attrs.items()
    File "/home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/setuptools/_distutils/dist.py", line 293, in __init__
      self.finalize_options()
    File "/home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/setuptools/dist.py", line 837, in finalize_options
      ep(self)
    File "/home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/setuptools/dist.py", line 858, in _finalize_setup_keywords
      ep.load()(self, ep.name, value)
    File "/home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/cffi/setuptools_ext.py", line 219, in cffi_modules
      add_cffi_module(dist, cffi_module)
    File "/home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/cffi/setuptools_ext.py", line 49, in add_cffi_module
      execfile(build_file_name, mod_vars)
    File "/home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/cffi/setuptools_ext.py", line 25, in execfile
      exec(code, glob, glob)
    File "raylib/build.py", line 197, in <module>
      build_unix()
    File "raylib/build.py", line 101, in build_unix
      raise Exception("ERROR: raylib not found by pkg-config.  Please install pkg-config and Raylib.")
  Exception: ERROR: raylib not found by pkg-config.  Please install pkg-config and Raylib.
  not windows, trying Unix build
  ----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/a7/55/d3d4524153e3d8af1736a934db11cd43e990cc234e1747c9a37e2c905573/raylib-4.0.0.1.tar.gz#sha256=75d23b4fd10bc796a3c23b14ab3b8675cc227cfbbd1750cf923d0fc007f7f093 (from https://pypi.org/simple/raylib/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
  Downloading raylib-4.0.0.tar.gz (54 kB)
     |████████████████████████████████| 54 kB 67 kB/s             
  Preparing metadata (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /home/pi/programs/depthAI_VIO/venv/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-3g4pioco/raylib_aecfaedebce145da8f909ab9e0d8b993/setup.py'"'"'; __file__='"'"'/tmp/pip-install-3g4pioco/raylib_aecfaedebce145da8f909ab9e0d8b993/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-eim523ku
       cwd: /tmp/pip-install-3g4pioco/raylib_aecfaedebce145da8f909ab9e0d8b993/
  Complete output (28 lines):
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/tmp/pip-install-3g4pioco/raylib_aecfaedebce145da8f909ab9e0d8b993/setup.py", line 42, in <module>
      cffi_modules=["raylib/build.py:ffibuilder"]
    File "/home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/setuptools/__init__.py", line 155, in setup
      return distutils.core.setup(**attrs)
    File "/home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/setuptools/_distutils/core.py", line 109, in setup
      _setup_distribution = dist = klass(attrs)
    File "/home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/setuptools/dist.py", line 463, in __init__
      for k, v in attrs.items()
    File "/home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/setuptools/_distutils/dist.py", line 293, in __init__
      self.finalize_options()
    File "/home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/setuptools/dist.py", line 837, in finalize_options
      ep(self)
    File "/home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/setuptools/dist.py", line 858, in _finalize_setup_keywords
      ep.load()(self, ep.name, value)
    File "/home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/cffi/setuptools_ext.py", line 219, in cffi_modules
      add_cffi_module(dist, cffi_module)
    File "/home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/cffi/setuptools_ext.py", line 49, in add_cffi_module
      execfile(build_file_name, mod_vars)
    File "/home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/cffi/setuptools_ext.py", line 25, in execfile
      exec(code, glob, glob)
    File "raylib/build.py", line 197, in <module>
      build_unix()
    File "raylib/build.py", line 101, in build_unix
      raise Exception("ERROR: raylib not found by pkg-config.  Please install pkg-config and Raylib.")
  Exception: ERROR: raylib not found by pkg-config.  Please install pkg-config and Raylib.
  not windows, trying Unix build
  ----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/de/c4/34fc0a91acd1ee2d8730011e72137f85827e42415378bb259ef3071fb6c4/raylib-4.0.0.tar.gz#sha256=8e45b34e3ba07f6701112e5e880fe31910dde0fd23b7717379229d8f4e90cd1c (from https://pypi.org/simple/raylib/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
  Downloading raylib-3.7.0.post10.tar.gz (71 kB)
     |████████████████████████████████| 71 kB 782 bytes/s         
  Preparing metadata (setup.py) ... done
Collecting cffi>=1.14.5
  Using cached https://www.piwheels.org/simple/cffi/cffi-1.15.0-cp37-cp37m-linux_armv7l.whl (346 kB)
Collecting inflection
  Using cached https://www.piwheels.org/simple/inflection/inflection-0.5.1-py2.py3-none-any.whl (9.5 kB)
Collecting pycparser
  Using cached https://www.piwheels.org/simple/pycparser/pycparser-2.21-py2.py3-none-any.whl (119 kB)
Skipping wheel build for raylib, due to binaries being disabled for it.
Installing collected packages: pycparser, inflection, cffi, raylib
  Attempting uninstall: pycparser
    Found existing installation: pycparser 2.21
    Uninstalling pycparser-2.21:
      Successfully uninstalled pycparser-2.21
  Attempting uninstall: inflection
    Found existing installation: inflection 0.5.1
    Uninstalling inflection-0.5.1:
      Successfully uninstalled inflection-0.5.1
  Attempting uninstall: cffi
    Found existing installation: cffi 1.15.0
    Uninstalling cffi-1.15.0:
      Successfully uninstalled cffi-1.15.0
  Attempting uninstall: raylib
    Found existing installation: raylib 4.0.0.2
    Uninstalling raylib-4.0.0.2:
      Successfully uninstalled raylib-4.0.0.2
    Running setup.py install for raylib ... error
    ERROR: Command errored out with exit status 1:
     command: /home/pi/programs/depthAI_VIO/venv/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-3g4pioco/raylib_bb4df5960072439892a892ce099daa53/setup.py'"'"'; __file__='"'"'/tmp/pip-install-3g4pioco/raylib_bb4df5960072439892a892ce099daa53/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-orvk_7n5/install-record.txt --single-version-externally-managed --compile --install-headers /home/pi/programs/depthAI_VIO/venv/include/site/python3.7/raylib
         cwd: /tmp/pip-install-3g4pioco/raylib_bb4df5960072439892a892ce099daa53/
    Complete output (34 lines):
    BUILDING FOR RASPBERRY PI
    running install
    /home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/setuptools/command/install.py:37: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
      setuptools.SetuptoolsDeprecationWarning,
    running build
    running build_py
    creating build
    creating build/lib.linux-armv7l-3.7
    creating build/lib.linux-armv7l-3.7/raylib
    copying raylib/version.py -> build/lib.linux-armv7l-3.7/raylib
    copying raylib/colors.py -> build/lib.linux-armv7l-3.7/raylib
    copying raylib/pyray.py -> build/lib.linux-armv7l-3.7/raylib
    copying raylib/build.py -> build/lib.linux-armv7l-3.7/raylib
    copying raylib/__init__.py -> build/lib.linux-armv7l-3.7/raylib
    creating build/lib.linux-armv7l-3.7/pyray
    copying pyray/__init__.py -> build/lib.linux-armv7l-3.7/pyray
    running egg_info
    warning: no files found matching 'raylib/*.so'
    warning: no files found matching 'raylib/*.pyd'
    warning: no previously-included files found matching 'raylib/*.a'
    warning: no previously-included files found matching 'raylib/*.c'
    warning: no previously-included files found matching 'raylib/*.o'
    writing manifest file 'raylib.egg-info/SOURCES.txt'
    copying raylib/__init__.pyi -> build/lib.linux-armv7l-3.7/raylib
    copying raylib/raylib.h -> build/lib.linux-armv7l-3.7/raylib
    copying raylib/raylib_modified.h -> build/lib.linux-armv7l-3.7/raylib
    running build_ext
    creating build/temp.linux-armv7l-3.7
    creating build/temp.linux-armv7l-3.7/build
    creating build/temp.linux-armv7l-3.7/build/temp.linux-armv7l-3.7
    arm-linux-gnueabihf-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -flto -fuse-linker-plugin -ffat-lto-objects -fPIC -I/home/pi/programs/depthAI_VIO/venv/include -I/usr/include/python3.7m -c build/temp.linux-armv7l-3.7/raylib._raylib_cffi.c -o build/temp.linux-armv7l-3.7/build/temp.linux-armv7l-3.7/raylib._raylib_cffi.o
    arm-linux-gnueabihf-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/temp.linux-armv7l-3.7/build/temp.linux-armv7l-3.7/raylib._raylib_cffi.o -L/usr/lib -o build/lib.linux-armv7l-3.7/raylib/_raylib_cffi.abi3.so /usr/local/lib/libraylib.a /opt/vc/lib/libEGL_static.a /opt/vc/lib/libGLESv2_static.a -L/opt/vc/lib -lvcos -lbcm_host -lbrcmEGL -lbrcmGLESv2 -lm -lpthread -lrt
    arm-linux-gnueabihf-gcc: error: /usr/local/lib/libraylib.a: No such file or directory
    error: command '/usr/bin/arm-linux-gnueabihf-gcc' failed with exit code 1
    ----------------------------------------
  Rolling back uninstall of raylib
  Moving to /home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/pyray/
   from /home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/~yray
  Moving to /home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/raylib-4.0.0.2.dist-info/
   from /home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/~aylib-4.0.0.2.dist-info
  Moving to /home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/raylib/
   from /home/pi/programs/depthAI_VIO/venv/lib/python3.7/site-packages/~aylib
ERROR: Command errored out with exit status 1: /home/pi/programs/depthAI_VIO/venv/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-3g4pioco/raylib_bb4df5960072439892a892ce099daa53/setup.py'"'"'; __file__='"'"'/tmp/pip-install-3g4pioco/raylib_bb4df5960072439892a892ce099daa53/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-orvk_7n5/install-record.txt --single-version-externally-managed --compile --install-headers /home/pi/programs/depthAI_VIO/venv/include/site/python3.7/raylib Check the logs for full command output.
`
electronstudio commented 2 years ago

I have raylib-python-cffi working on X11 with RP3, I think that should also work on RP4.

First, as I already said, to eliminate your first error you will need to install Raylib using cmake. Instructions are here https://github.com/raysan5/raylib/wiki/Working-on-GNU-Linux#build-raylib-using-cmake but basically it is this:

      cd raylib-4.0.0
      mkdir build
      cd build
      cmake  -DWITH_PIC=on -DCMAKE_BUILD_TYPE=Release  -DOpenGL_GL_PREFERENCE=GLVND ..
      make
      sudo make install

Then install the new rraylib-python-cffi release I just put out

pip3 install raylib==4.0.0.3

To do native graphics on RP4 you would have to edit https://github.com/electronstudio/raylib-python-cffi/blob/master/raylib/build.py with whatever build flags are required for Raylib programs in this mode. I don't have RP4 so can't do much without access to one.

TheBricktop commented 2 years ago

Will do, im getting to it .

electronstudio commented 2 years ago

Raylib currently has unresolved issues with native RPI4 support https://github.com/raysan5/raylib/issues/2259

So we need that to be fixed, and we need someone with a RPI4.

TheBricktop commented 2 years ago

That'd be me While im currently using panda3d and panda 3d accesories (like ursina).

electronstudio commented 2 years ago

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

I haven't tested on RPI4 but the OS is the same, so if Raylib works then the bindings should work.

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.