cnr-isti-vclab / PyMeshLab

The open source mesh processing python library
GNU General Public License v3.0
770 stars 62 forks source link

PyMeshLab and libGL.so.1 dependency #393

Closed niko-zvt closed 1 week ago

niko-zvt commented 1 week ago

Hi,

I've encountered an issue when trying to use pymeshlab in a python:3.10 container that does not include OpenGL or the X-windows system. Here's the error message:

  File "/home/user/app/submodule/__init__.py", line 34, in process
    import pymeshlab

  File "/usr/local/lib/python3.10/site-packages/pymeshlab/__init__.py", line 11, in <module>
    from .pmeshlab import *

ImportError: libGL.so.1: cannot open shared object file: No such file or directory

This error does not occur when running the container with the X-windows system, and pymeshlab works fine in that setup.

Questions:

  1. Why is pymeshlab dependent on libGL.so.1 even when running in headless mode without any graphical user interface requirements?
  2. Is there a way to configure or compile pymeshlab to work in an environment without OpenGL and the X-windows system, or is this library inherently dependent on these components?

Context:

I appreciate any insights into why this dependency is required and possible solutions for running pymeshlab in a headless container environment.

I also found a script to initialize the environment: PyMeshLab > scripts > Linux > 0_setup_env.sh

#!/bin/bash

sudo apt-get install -y mesa-common-dev libglu1-mesa-dev
sudo apt-get install -y make ninja-build patchelf libgmp-dev libmpfr-dev libxerces-c-dev
sudo apt-get install -y libtbb-dev

#needed by qt 5.15 on linux
sudo apt-get install libxkbcommon-x11-dev libxcb-icccm4-dev libxcb-image0-dev libxcb-keysyms1-dev libxcb-render-util0-dev libxcb-xinerama0-dev

Thanks!

alemuntoni commented 1 week ago
  1. Why is pymeshlab dependent on libGL.so.1 even when running in headless mode without any graphical user interface requirements?

Because pymeshlab is based on meshlab, which has a codebase that is not as modular as it could be. A huge refactoring (or rewriting) is required to remove this dependency. Moreover, some pymeshlab functions (or meshlab filters) use opengl to perform their computations (it would be easy to make these plugins 'optional', but it would be pointless since pymeshlab itself needs opengl).

  1. Is there a way to configure or compile pymeshlab to work in an environment without OpenGL and the X-windows system, or is this library inherently dependent on these components?

Not at the moment, unfortunately.

niko-zvt commented 1 week ago

@alemuntoni , Thanks for your reply. Yes, indeed, I was able to assemble a container that has all the required dependencies and everything worked.

I am giving a list of packages that I use. The list may be too extensive, perhaps some of this is not necessary. I'll leave it here if someone needs to run pymeshlab in a container without a GUI.

    software-properties-common
    gcc
    make
    mesa-common-dev
    libglu1-mesa-dev
    ninja-build
    patchelf
    libgmp-dev
    libmpfr-dev
    libxerces-c-dev
    libtbb-dev