Python PyQT6 can't find libgl.so.1 shared object

I’m trying to run a Python PyQt6 application so that I can develop it. So I’m trying to get this to work in a development environment. When trying to run the application with python main.py I get the error following error:

Traceback (most recent call last):
  File "/home/user/Project/main.py", line 3, in <module>
    from PyQt6.QtWidgets import *
ImportError: libGL.so.1: cannot open shared object file: No such file or directory

Presumably the interpreter can not find the OpenGL library object. After running ls /run/current-system/sw/lib/ -lat | grep libgl, it returns nothing. There doesn’t seem to by any OpenGL libraries installed on the system. Maybe they got installed somewhere else?

So far, what I’ve tried is adding the python311Packages.pyopengl package to my nix configuration. I’m using home manager so I put this in my home.nix file right after my python entry. I’ve included a snippet of my home.nix configuration for completeness.

home.nix file
{
  home.packages = with pkgs; [
    # Add packages to just this user
    zoxide
    fzf
    lsd
    gcc
    xclip

    python313Full
    poetry
    python311Packages.pyopengl
  ];
}

Not sure if it’s relevant, but I’m using the i3 desktop environment which I think is why I’m having the issue of no OpenGL libraries.

I then tried using the nix-ld program found here. When using nix-ld I tried adding the python311Packages.pyopengl package as before with home managers as well as libGL; neither of these seemed to include a new libgl object anywhere. I also check the /lib and /lib64 files for a new object.

My question here is how can I install the OpenGL shared object for the system? I would prefer to do it in my user configuration if possible (I also have a users.nix file to include programs in) because of the way I’ve structured my users’ configurations.

set LD_LIBRARY_PATH environment variables, put export LD_LIBRARY_PATH=${pkgs.libGL}/lib/ in your shell init script to solve the problem (${pkgs.libGL} is the libGL install dir, so you should use nix configurtion to parse it, such as use home.file.".zshrc".text = "export LD_LIBRARY_PATH=${pkgs.libGL}/lib/" in home-manager). If have other lib files the python not found, use : to split multiple lib dir path, such as export LD_LIBRARY_PATH=${pkgs.libGL}/lib/:${pkgs.stdenv.cc.cc.lib}/lib/

If you use flake, see nix-templates/python-venv at a6eba33074da4a7079f63124ebfbb2369a4f9540 · MordragT/nix-templates · GitHub