FlorianRhiem / pyGLFW

Python bindings for GLFW
MIT License
232 stars 36 forks source link

Support lloading glfw3.so from LD_LIBRARY_PATH #14

Closed paulmelis closed 7 years ago

paulmelis commented 7 years ago

This is with pyglfw 1.3.3 on Linux. The _load_library call in glfw.py uses a fixed set of paths that it searches for the GLFW shared lib. Unfortunately, I don't have GLFW3 installed system-wide as the available Debian package on jessie is a bit old. So I compiled and installed the latest GLFW3 in a custom location (/software/glfw/3.2.1 in this case), but I can't direct pyglfw to get the shared lib from there without hacking glfw.py.

Here's an updated excerpt of glfw.py, starting around line 150, to make it search the paths in LD_LIBRARY_PATH as well:

if sys.platform == 'win32':

only try glfw3.dll on windows

try:
    _glfw = ctypes.CDLL('glfw3.dll')
except OSError:
    _glfw = None

else: search_paths = [ '', '/usr/lib64', '/usr/local/lib64', '/usr/lib', '/usr/local/lib', '/run/current-system/sw/lib', '/usr/lib/x86_64-linux-gnu/' ]

if 'LD_LIBRARY_PATH' in os.environ:
    search_paths.extend(os.environ['LD_LIBRARY_PATH'].split(':'))

_glfw = _load_library(['glfw', 'glfw3'], ['.so', '.dylib'],
                      search_paths, _glfw_get_version)
FlorianRhiem commented 7 years ago

Hello Paul, thank you for the suggestion. This is indeed something that should be used for the library search! LD_LIBRARY_PATH is used on Linux and DYLD_LIBRARY_PATH is used on macOS. So I'd suggest having this dependent on sys.platform, with Linux behavior as default/fallback. Also, an environment variable PYGLFW_LIBRARY should allow the user to set what library should be used. That way, if you want to use a specific binary, you can be sure that another library with the same version won't be used instead. What do you think?

Edit: Windows doesn't matter, as ctypes does the searching for us there. Added PYGLFW_LIBRARY.

FlorianRhiem commented 7 years ago

Please take a look at 8824afb59d55f4769797c4f60aeecc45cb09a94e and let me know what you think.

paulmelis commented 7 years ago

Hi Florian, Looks great!

FlorianRhiem commented 7 years ago

Version 1.4.0 is on PyPI now. Thanks again!