raylib-py icon indicating copy to clipboard operation
raylib-py copied to clipboard

'_rl' is not defined

Open matcool opened this issue 5 years ago • 4 comments

I'm trying to run one of the examples:

import os
os.environ["RAYLIB_BIN_PATH"] = "libraylib.dll"

from raylibpy import *

init_window(800, 450, "raylib [core] example - basic window")

set_target_fps(60)

while not window_should_close():

    begin_drawing()
    clear_background(RAYWHITE)
    draw_text("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY)
    end_drawing()

close_window()

and im getting the error:

Traceback (most recent call last):
  File "rlibtest.py", line 4, in <module>
    from raylibpy import *
  File "C:\Users\Mateus\AppData\Local\Programs\Python\Python37\lib\site-packages\raylibpy\__init__.py", line 2695, in <module>
    _rl.InitWindow.argtypes = [Int, Int, CharPtr]
NameError: name '_rl' is not defined

matcool avatar Jul 24 '19 22:07 matcool

I know this response is a bit late, but to try to at least close the issue... The import is failing to find the library. I ran your code (on a Mac) and got the same traceback (just, with a different path). I then tried removing the first two lines and running your code from a directory that contains a copy of the RayLibPy module (so I knew the import would succeed), and everything worked correctly.

You just need to figure out how to link everything together, but I don't know much about Windows, so don't know what to suggest.

carlsmith avatar Aug 21 '19 22:08 carlsmith

I have just tested running without the first two lines, and it seems to find the file but it now runs into this issue:

Traceback (most recent call last):
  File "raylibtest.py", line 1, in <module>
    from raylibpy import *
  File "C:\Users\Mateus\AppData\Local\Programs\Python\Python37\lib\site-packages\raylibpy\__init__.py", line 72, in <module>
    _rl = CDLL(os.path.join(RAYLIB_BIN_PATH, _lib_filename[_platform]))
  File "C:\Users\Mateus\AppData\Local\Programs\Python\Python37\lib\ctypes\__init__.py", line 356, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 193] %1 is not a valid Win32 application

I have even tried modifying the module files to print the path its trying to open, and it is opening the corrent file. I have also tried using the raylib dll found here, but that doesn't seem to work as it is different from the shared one.

matcool avatar Aug 22 '19 23:08 matcool

os.environ["RAYLIB_BIN_PATH"] must be directory path. E.g. "__main__" (same directory as py file), "C:/project/". You can run without the first two lines if replace \Lib\site-packages\raylibpy\libraylib_shared.dll with worked one. I've tested Python 3.8.0 (x64) + libraylib_shared.dll from raylib-2.0.0-Win64-mingw.zip.

infval avatar Nov 06 '19 03:11 infval

The solution of @infval is working fine for me.

On Ubuntu :

I downloaded the raylib 2.0.0 (raylib-2.0.0-Linux-amd64), extracted it in my project. I was trying to use it form venv but without success... There is the 2 first lines of my python file :

import os
os.environ["RAYLIB_BIN_PATH"] = "raylib-2.0.0-Linux-amd64/lib/"

On Windows :

I downloaded the raylib 2.0.0 (raylib-2.0.0-Win64-mingw), extracted it in my project. There is the 2 first lines of my python file :

import os
os.environ["RAYLIB_BIN_PATH"] = "raylib-2.0.0-Win64-mingw/lib/"

CorentinLeGuen avatar May 21 '20 22:05 CorentinLeGuen