ImportError: dynamic module does not define module export function (PyInit_libgraph_tool_core)

Graph tool version 2.68
Operating system Centos 8

Hi, I am using this program surface morphometrics(GitHub - GrotjahnLab/surface_morphometrics: Morphometrics for Membrane Surfaces Segmented from Cryo-ET or other volumetric imaging.). The program uses graph-tool. When I execute the Program it had the following error ImportError: dynamic module does not define module export function (PyInit_libgraph_tool_core)

(morphometrics) kaezhila@blue  ~/software/surface_morphometrics-1.1 $ > python segmentation_to_meshes.py config.yml 
Info: Module sympy could not be loaded. However, this is not a problem for running Pyto, because sympy is currently used only for development.
Warning: Pyseg could not be loaded. Therefore, calling from_pyseg() method of pyto.spatial.ParticleSets will fail, but everything else should be fine.
Traceback (most recent call last):
  File "/home/kaezhila/software/surface_morphometrics-1.1/segmentation_to_meshes.py", line 25, in <module>
    import ply2vtp
  File "/home/kaezhila/software/surface_morphometrics-1.1/ply2vtp.py", line 16, in <module>
    from pycurv import pycurv_io as io
  File "/home/kaezhila/.local/lib/python3.9/site-packages/pycurv/__init__.py", line 9, in <module>
    from .graphs import SegmentationGraph
  File "/home/kaezhila/.local/lib/python3.9/site-packages/pycurv/graphs.py", line 5, in <module>
    from graph_tool import Graph
  File "/home/kaezhila/.conda/envs/morphometrics/lib/python3.9/site-packages/graph_tool/__init__.py", line 118, in <module>
    dl_import("from . import libgraph_tool_core as libcore")
  File "/home/kaezhila/.conda/envs/morphometrics/lib/python3.9/site-packages/graph_tool/dl_import.py", line 44, in dl_import
    exec(import_expr, local_dict, global_dict)
  File "<string>", line 1, in <module>
ImportError: dynamic module does not define module export function (PyInit_libgraph_tool_core)

Further details of how I installed the program and graph tool

name: morphometrics
dependencies:
  - conda-forge::python=3.9
  - conda-forge::pyqt
  - conda-forge::matplotlib=3.3.3
  - conda-forge::pandas
  - conda-forge::graph-tool
  - conda-forge::pathlib
  - conda-forge::pip>=20.0.2

Is there any work around this or could be solved?

Please report this problem either to the surface_morphometrics package or to conda-forge: Issues · conda-forge/graph-tool-feedstock · GitHub

Don’t forget to include a minimal working example, not only the error message.

Hi,

Thanks for your comments. I raised the issue first in surface morphometrics package. They advised me it could be a issue with graph-tool and asked me to check here.

A minimum working example

(morphometrics) kaezhila@blue  ~/software/surface_morphometrics-1.1 $ > python
Python 3.9.19 | packaged by conda-forge | (main, Mar 20 2024, 12:50:21) 
[GCC 12.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> # test_graph_tool.py
>>> try:
...     from graph_tool.all import Graph
...     print("graph-tool imported successfully")
... except ImportError as e:
...     print(f"ImportError: {e}")
... 
ImportError: dynamic module does not define module export function (PyInit_libgraph_tool_core)

As advised will report it to the conda-forge Issues · conda-forge/graph-tool-feedstock · GitHub

Well, I can’t reproduce this.

If I do:

git clone https://github.com/grotjahnlab/surface_morphometrics.git
cd surface_morphometrics
conda env create -f environment.yml
conda activate morphometrics

and then

$ python
Python 3.9.19 | packaged by conda-forge | (main, Mar 20 2024, 12:50:21) 
[GCC 12.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from graph_tool.all import Graph
>>> 

everything works just fine.

Apologies, I think missed some information

Once, I do the following

git clone https://github.com/grotjahnlab/surface_morphometrics.git
cd surface_morphometrics-1.1
conda env create -f environment.yml
conda activate morphometrics

I install the additional dependencies from

(morphometrics) kaezhila@kraken  ~/software/surface_morphometrics-1.1 $ > cat pip_requirements.txt 
git+https://github.com/vladanl/Pyto.git
git+https://github.com/kalemaria/pycurv.git
pymeshlab
pyyaml
click
mrcfile
scikit-learn
jupyter
statsmodels

(morphometrics) kaezhila@kraken  ~/software/surface_morphometrics-1.1 $ > pip install -r pip_requirements.txt

After that when I try to execute the program I get the following error

(morphometrics) kaezhila@kraken  ~/software/surface_morphometrics-1.1 $ >  python segmentation_to_meshes.py config.yml 
Info: Module sympy could not be loaded. However, this is not a problem for running Pyto, because sympy is currently used only for development.
Warning: Pyseg could not be loaded. Therefore, calling from_pyseg() method of pyto.spatial.ParticleSets will fail, but everything else should be fine.
Traceback (most recent call last):
  File "/home/kaezhila/software/surface_morphometrics-1.1/segmentation_to_meshes.py", line 25, in <module>
    import ply2vtp
  File "/home/kaezhila/software/surface_morphometrics-1.1/ply2vtp.py", line 16, in <module>
    from pycurv import pycurv_io as io
  File "/home/kaezhila/.local/lib/python3.9/site-packages/pycurv/__init__.py", line 9, in <module>
    from .graphs import SegmentationGraph
  File "/home/kaezhila/.local/lib/python3.9/site-packages/pycurv/graphs.py", line 5, in <module>
    from graph_tool import Graph
  File "/home/kaezhila/.conda/envs/morphometrics/lib/python3.9/site-packages/graph_tool/__init__.py", line 118, in <module>
    dl_import("from . import libgraph_tool_core as libcore")
  File "/home/kaezhila/.conda/envs/morphometrics/lib/python3.9/site-packages/graph_tool/dl_import.py", line 44, in dl_import
    exec(import_expr, local_dict, global_dict)
  File "<string>", line 1, in <module>
ImportError: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /home/kaezhila/.conda/envs/morphometrics/lib/python3.9/site-packages/graph_tool/libgraph_tool_core.so)

To sort out this import error. I do the following symbolic link

(morphometrics) kaezhila@kraken  ~/software/surface_morphometrics-1.1 $ > ln -sf /usr/lib64/libstdc++.so.6  /home/kaezhila/.conda/envs/morphometrics/lib/python3.9/site-packages/graph_tool/libgraph_tool_core.so

Then I execute the program, I get the error
ImportError: dynamic module does not define module export function (PyInit_libgraph_tool_core)

And now if I try the Minimum working example, it also fails

(morphometrics) kaezhila@kraken  ~/software/surface_morphometrics-1.1 $ > python
Python 3.9.19 | packaged by conda-forge | (main, Mar 20 2024, 12:50:21) 
[GCC 12.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> ImportError: dynamic module does not define module export function (PyInit_libgraph_tool_core
KeyboardInterrupt
>>> # test_graph_tool.py
>>> try:
...     from graph_tool.all import Graph
...     print("graph-tool imported successfully")
... except ImportError as e:
...     print(f"ImportError: {e}")
... 
ImportError: dynamic module does not define module export function (PyInit_libgraph_tool_core)

This is obviously not a problem with graph-tool, since it imports fine on its own, and I don’t have the patience to investigate which individual package that you include is somehow breaking things.

If you could try to isolate which individual package is causing the problem, that would be helpful.