No description
This repository has been archived on 2025-06-21. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
Find a file
2021-01-16 18:32:56 +00:00
examples fix issue #16 2020-11-16 08:45:37 +00:00
raylib update linux binaries to 3.5 (note using new glibc so may not work on old linuxes) 2021-01-16 18:32:38 +00:00
raylib-c@6631fc4c6d add raylib source as submodule so we know which version we are compatible with 2021-01-16 15:39:15 +00:00
.gitignore fix gitignore leaving out windows pyd library! 2019-05-26 00:29:19 +01:00
.gitmodules add raylib source as submodule so we know which version we are compatible with 2021-01-16 15:39:15 +00:00
coords_demo.py reorg modules 2019-06-07 03:51:03 +01:00
LICENSE Initial commit 2019-05-21 10:53:59 +01:00
MANIFEST.in 2.5.0post1 release 2019-06-06 04:15:54 +01:00
README.md Update README.md 2021-01-16 18:30:23 +00:00
setup.py update linux binaries to 3.5 (note using new glibc so may not work on old linuxes) 2021-01-16 18:32:38 +00:00
test_dynamic.py add pythonic wrapper, pyray 2019-05-26 20:24:57 +01:00
test_pyray.py automatically deref pointers in pyray 2020-09-19 10:12:30 +01:00
test_static.py add pythonic wrapper, pyray 2019-05-26 20:24:57 +01:00
windows_is_shit.bat windows 64 bit 2020-02-14 11:50:25 -08:00

Python Bindings for Raylib 3.5

New CFFI API static bindings. Faster, fewer bugs and easier to maintain than ctypes.

Advert

RetroWar: 8-bit Party Battle is out now. Defeat up to 15 of your friends in a tournament of 80s-inspired retro mini games.

Install

Install from Pypi (easiest)

Windows 10 (64 bit): Python 3.6 - 3.8

MacOS: Python 3.6 - 3.8

Linux (Ubuntu 16.04+): Python 3.6 - 3.8

We distribute a statically linked Raylib library, install from Pypi.

pip3 install raylib

Install from github

The version on Pypi may not always be up to date. If you want to test the very latest version, clone the git repo and make a symlink to the raylib directory in your current project directory.

Build from source

If you're a different version of Python, or a Linux with incompatible libraries then you can either use the dynamic binding only or else you will have to build from source.

Clone this repo including submodules so you get correct version of Raylib.

git clone --recurse-submodules https://github.com/electronstudio/raylib-python-cffi

Build and install Raylib from the raylib-c directory.

cd raylib-python-cffi/raylib-c
mkdir build
cd build
cmake -DWITH_PIC=on -DSTATIC=on -DSHARED=on ..
sudo make install

Make a patched version of raylib header.

cd ../../raylib
cp raylib.h raylib_modified.h
patch  -p0 <raylib_modified.h.patch

Build

cd static
pip3 install cffi
python3 build_linux.py

To build a complete set of libs for Python 3.6, 3.7, 3.8 and 3.9:

./build_linux_multi.sh

To update the dynamic libs too:

cd ../..
rm raylib/dynamic/*.so*
cp --preserve=links /usr/local/lib/libraylib.so* raylib/dynamic/

Use

raylib.static

Goal is make usage as similar to the original C as CFFI will allow. There are a few differences you can see in the examples. See test_static.py and examples/*.py for how to use.

from raylib.static import *

InitWindow(800, 450, b"Hello Raylib")
SetTargetFPS(60)

camera = ffi.new("struct Camera3D *", [[18.0, 16.0, 18.0], [0.0, 0.0, 0.0], [0.0, 1.0, 0.0], 45.0, 0])
SetCameraMode(camera[0], CAMERA_ORBITAL)

while not WindowShouldClose():
    UpdateCamera(camera)
    BeginDrawing()
    ClearBackground(RAYWHITE)
    BeginMode3D(camera[0])
    DrawGrid(20, 1.0)
    EndMode3D()
    DrawText(b"Hellow World", 190, 200, 20, VIOLET)
    EndDrawing()
CloseWindow()

raylib.pyray

Wrapper around the static bindings. Makes the names snakecase and converts strings to bytes automatically. See test_pyray.py.

from raylib.pyray import PyRay
from raylib.colors import *

pyray = PyRay()

pyray.init_window(800, 450, "Hello Pyray")
pyray.set_target_fps(60)

camera = pyray.Camera3D([18.0, 16.0, 18.0], [0.0, 0.0, 0.0], [0.0, 1.0, 0.0], 45.0, 0)
pyray.set_camera_mode(camera, pyray.CAMERA_ORBITAL)

while not pyray.window_should_close():
    pyray.update_camera(pyray.pointer(camera))
    pyray.begin_drawing()
    pyray.clear_background(RAYWHITE)
    pyray.begin_mode_3d(camera)
    pyray.draw_grid(20, 1.0)
    pyray.end_mode_3d()
    pyray.draw_text("Hello world", 190, 200, 20, VIOLET)
    pyray.end_drawing()
pyray.close_window()

raylib.dynamic

In addition to the API static bindings we have CFFI ABI dynamic bindings in order to avoid the need to compile a C extension module. There have been some weird failures with dynamic bindings and ctypes bindings before and often the failures are silent so you dont even know. Also the static bindings should be faster. Therefore I recommend the static ones...

BUT the dynamic bindings have the big advantage that you don't need to compile anything to install. You just need a Raylib DLL, which we supply for Windows/Mac/Linux.

See test_dynamic.py for how to use.

richlib

A simplified API for Raylib for use in education and to enable beginners to create 3d games

Platforms tested

  • (MacOS 10.12.6 - Python 3.7)
  • (Ubuntu 18.04 LTS - Python 3.6)
  • Debian 10 - Python 3.7
  • Windows 10 (64 bit) - Python 3.8

HELP WANTED

  • converting more examples from C to python
  • testing and building on more platforms
  • sorting out binary wheel distribution for Mac/Win and compile-from-source distributtion for Linux