mcfletch / pyopengl

Repository for the PyOpenGL Project
Other
314 stars 97 forks source link

Looking for a way to silence numpy error on startup? #98

Closed TTimo closed 1 year ago

TTimo commented 1 year ago

Hello,

Whenever my app does import OpenGL.GL as gl I get a message Unable to import OpenGL.arrays.numpymodule.NumpyHandler: No numpy module present: No module named 'numpy'

I know this is benign - I don't use numpy and it's not installed. But it often confuses my users into thinking there's a problem, so I'd like a way to silence it?

mcfletch commented 1 year ago

The simplest way would likely be to add this to the top of your main script:

import logging

logging.basicConfig(level=logging.INFO)
logging.getLogger('OpenGL.plugins').setLevel(logging.ERROR)

# Test that it works...
from OpenGL.arrays import arraydatatype

dt = arraydatatype.GLuintArray
d = dt.zeros((3,))

which should suppress all warning-and-below messages from the plugins module.

If you have a more complex logging config, then you'll have to figure out how to set the level on the plugins directory within that framework.

HTH

TTimo commented 1 year ago

Thank you! Very nice solution, worked out fine.