Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using a macOS 12.2.1 with Python 3.10 and I am trying to install Raylib Python CFFI 3.7 or higher but whenever I run the `python3 -m pip install raylib` command or the `pip3 install raylib` command but I keep getting the error below:

generating cffi module 'build/temp.macosx-10.9-universal2-3.10/raylib._raylib_cffi.c'
building 'raylib._raylib_cffi' extension
build/temp.macosx-10.9-universal2-3.10/raylib._raylib_cffi.c:570:14: fatal error: 'raylib.h' file not found
#include "raylib.h"
^~~~~~~~~~
1 error generated.
error: command '/usr/bin/clang' failed with exit code 1
[end of output]


I tried several things to solve this issue but no luck.

What I have tried:

I tried installing other libraries by running these commands
pip3 install --upgrade setuptools
pip3 install ez_setup
python3 -m pip install --upgrade pip
pip install --upgrade setuptools
brew install pkg-config
brew install raylib
python3 -m pip install pyray
Then I was getting an error in the VideoService class on line 101 pyray.init_window(self.width, self.height, self.caption) basically that the function init_window() did not exist in pyray so I installed the raylib dynamic library by executing this command python3 -m pip install raylib_dynamic
So now I have the below list of libraries:
% pip list
Package Version
-------------- -------
cffi 1.15.0
ez-setup 0.9
inflection 0.5.1
pip 22.0.3
pycparser 2.21
pyray 0.1.0
raylib-dynamic 4.0.0.5
setuptools 60.8.2
Note that I already added the Artifact class code in the artifact.py file
And now I am getting this error when I run the game python3 rfk:
File "/Users/gibran/Documents/cse210-06/rfk/game/services/keyboard_service.py", line 1, in <module>
import pyray
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pyray/_init_.py", line 15, in <module>
from raylib import rl, ffi
ImportError: cannot import name 'rl' from 'raylib' (/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/raylib/_init_.py)

I installed rl by executing python3 -m pip install rl
Collecting rl
Downloading rl-3.0.zip (448 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 448.3/448.3 KB 7.8 MB/s eta 0:00:00
Preparing metadata (setup.py) ... done
Requirement already satisfied: setuptools in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from rl) (60.8.2)
Using legacy 'setup.py install' for rl, since package 'wheel' is not installed.
Installing collected packages: rl
Running setup.py install for rl ... done
Successfully installed rl-3.0

But no luck and installed python3 -m pip install raylib-py but no luck
% pip list
Package Version
-------------- -------
cffi 1.15.0
ez-setup 0.9
inflection 0.5.1
pip 22.0.3
pycparser 2.21
pyray 0.1.0
raylib-dynamic 4.0.0.5
raylib-py 0.1.1
rl 3.0
setuptools 60.8.2
Posted
Updated 15-Feb-22 17:48pm
v2
Comments
Richard MacCutchan 15-Feb-22 4:11am    
The error message tells you that the file raylib.h is not found. You need to check to the distribution package stored at build/temp.macosx-10.9-universal2-3.10 to see if it is there, or stored elsewhere. If the file is definitely missing then you should check its download location.
Gibran Castillo 15-Feb-22 13:09pm    
Modify the comment. Delete the comment.
Hi @Richard - what is the root path of build/temp.macosx-10.9-universal2-3.10 ?
Richard MacCutchan 16-Feb-22 3:16am    
No idea. Look on your system.

1 solution

My macOS is using an Apple M1 Max chip and it looks like my macOS is having compilation issues with raylib.

If you have an M1 based Mac, you should create a Rosetta based terminal and work within that terminal by following these steps below [ONLY FOR macOS M1].

- Locate the Terminal application within the Utilities folder (Finder > Go menu > Utilities)
- Select Terminal.app and right-click on it, then choose “Duplicate”.
- Rename the duplicated Terminal app something obvious and distinct, like ‘Rosetta Terminal’.
- Now select the freshly renamed ‘Rosetta Terminal’ app and right-click and choose “Get Info” (or hit Command+i)
- Check the box for “Open using Rosetta”, then close the Get Info window.
- Run the “Rosetta Terminal” as usual, which will fully support Homebrew and other x86 command line apps.

- In the “Rosetta Terminal”, first ensure pip is upgraded python3 -m pip install --upgrade pip and then install raylib python3 -m pip install raylib

- Then you should be able to run your raylib based python game.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900