-1

I am attempting to create an executable program out of a Python project that uses moderngl. Here is a minimal example that just creates a window and waits til it's quit:

import moderngl as mgl
import pygame as pg

pg.init()
screen = pg.display.set_mode((800, 600), pg.DOUBLEBUF | pg.OPENGL)
gl_ctx = mgl.create_context(require=330)

clock = pg.time.Clock()
while True:
    for event in pg.event.get():
        if event.type == pg.QUIT:
            pg.quit()
            quit()
    clock.tick(30)

I run

pyinstaller --onefile test_gl.py

on my command line and get a .exe file placed in the /dist directory. What I would expect is that when I run that .exe, it brings up the blank window like when I run the python script. Instead, I get the error message:

Traceback (most recent call last):
  File "test_gl.py", line 6, in <module>
  File "moderngl\context.py", line 1619, in create_context
ModuleNotFoundError: No module named 'glcontext'
[7428] Failed to execute script 'test_gl' due to unhandled exception!

So it seems something necessary is not being packaged into the executable, but I am not sure as to what needs to be changed to get it included, if it is even possible at all. I had thought PyInstaller automatically packages dependencies.

I have Python 3.10.4, PyInstaller 4.10, PyGame 2.1.2( SDL 2.0.18, Python 3.10.4 ), and moderngl 5.6.4

user2649681
  • 750
  • 1
  • 6
  • 23

1 Answers1

0

Turns out secondary dependencies aren't necessarily added by PyInstaller, so using --hidden-import glcontext solved the issue (or adding 'glcontext' to hidden_imports in the .spec file)

user2649681
  • 750
  • 1
  • 6
  • 23