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

Raylib not working : cannot import 'rl' #59

Closed BIueish closed 2 years ago

BIueish commented 2 years ago

I'm on MacOS 12.1 and I installed Raylib using pip. I import it via from pyray import * but it resulted in the error

  File "raylib.py", line 1, in <module>
    from pyray import *
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pyray/__init__.py", line 15, in <module>
    from raylib import rl, ffi
ImportError: cannot import name 'rl' from 'raylib' (/Users/samate/PycharmProjects/MyPrograms/raylib.py)

I built raylib from source using pip but it resulted in the same error. Previous versions didn't work too. I tried from raylib import * and this gave a different error

  File "raylib.py", line 26, in <module>
    main()
  File "raylib.py", line 6, in main
    InitWindow(800, 450, b'hello world')
NameError: name 'InitWindow' is not defined

Finally trying from raylib import rl results in:

  File "raylib.py", line 1, in <module>
    from raylib import rl
  File "raylib.py", line 1, in <module>
    from raylib import rl
ImportError: cannot import name 'rl' from partially initialized module 'raylib' (most likely due to a circular import) (raylib.py)
electronstudio commented 2 years ago

In Python, can't name your own program the same name as a library you are importing.

BIueish commented 2 years ago

oh sorry what a dumb mistake i should have known better :(

electronstudio commented 2 years ago

Don’t worry, we all make them.