electronstudio / raylib-python-cffi

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

PyInstaller Build Producing Broken Executable #3

Closed Pebaz closed 4 years ago

Pebaz commented 5 years ago

Trying to test distribution of Raylib-Python-CFFI projects:

# hello-world.py
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()

Now to build it

pyinstaller --onefile hello-world.py

# Test it
dist/hello-world.py

Error message

Traceback (most recent call last):
  File "hello-world.py", line 1, in <module>
    from raylib.static import *
  File "c:\python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages\raylib\static\__init__.py", line 1, in <module>
ModuleNotFoundError: No module named '_cffi_backend'
[7316] Failed to execute script hello-world
Pebaz commented 5 years ago

Found solution:

pyinstaller --onefile --hidden-import=cffi hello-world.py

Explaination

PyInstaller did not know that it needed to bundle CFFI, so adding the --hidden-import=cffi successfully added CFFI to the EXE bundle.

electronstudio commented 5 years ago

I will add an explicit import cffi if it fixes this

Pebaz commented 5 years ago

I just tested this theory by adding import cffi to my test module's code and this worked perfectly! I am assuming that if you add that to the base code that it will accomplish the same effect. Good thinking!