Search code examples
pythongraphnullloadigraph

Cannot load graphs. Loading graph to igraph (from arbitrary source) "returned NULL"


I am working with igraph and networkx and I try to convert my nx graph to an igraph graph via

nx.write_graphml(nx_graph,filepath) # Export NX graph to file
ig_graph = ig.read(filepath,format="graphml") # Create new IG graph from file

This works perfectly fine on one machiene, but on another one I get the error

SystemError: built-in method Read_GraphML of type object at 0x000002488D3FEE58 returned NULL without setting an error

I run Windows10 and Python 3.5. Interestingly, on the working machine the python-igraph version is specified as '0.7.1' while on the faulty system it is '0.7.1+5.3b99dbf6' although I am rather sure to have done the same install procedure via the files from Christoph Gohlke.

The error also occurs in a simple test setting like this:

import igraph as ig
g = ig.Graph.Famous("zachary")
g.save("zachary.graphml")
g=ig.load("zachary.graphml")

Thus, I am pretty sure is has nothing to do with the file that was produced by networkx but rather it has to be something wrong with my igraph configuration. I really do not know where the difference on the systems may be, so please let me know if you have any ideas.

Thank you! :)

Edit: I did also run the test suite

import igraph.test
igraph.test.run_tests()

and it worked well on both setups - even the faulty one.


Solution

  • I think that you are hitting a known bug in python-igraph's file handling routines that manifests itself only on Python 3.x (but not on Python 2.x). This is the issue in the bug tracker; this is the explanation and this is the patch that fixes it. Unfortunately, since there was no new release since the patch, you will need to recompile igraph on your own to get rid of it.

    However, note that the bug is triggered only if there is an error (exception) while trying to load the graph. My first guess would be that igraph on the second system was built without GraphML support, so the loader throws an exception while reading the file (stating that there is no GraphML support in this build), which in turn triggers the bug.