Gtk version conflict (I think?)

Hi there!

I want to use graph_tool for my thesis but I can’t even get the first quickstart example to run. I am getting the error message “ValueError: Namespace Gtk is already loaded with version 4.0” as soon as the graph_tool.all import happens. I am assuming this is a versioning error but I could not find any documentation online on which gtk version graph_tool needs or how to mitigate a version conflict. Nor could I find anyone with the same problem as me, which is why I am asking here. I could of course start removing different Gtk versions but I’m not sure what packages might break so I would rather not do that without good reason. Any help or directions to sources that might help would be much appreciated! Cheers.

OS is Linux (Solus) and graph-tool version is 2.45-17.

Unfortunately, it’s not possible to provide a solution to your problem or an answer to your question with the information provided.

To enable us to understand the situation, you need to provide all the items below:

  1. Your exact graph-tool version.
  2. Your operating system.
  3. A minimal working example that shows the problem.

Item 3 above is very important! If you provide us only the part of the code that you believe causes the problem, then it is not possible to understand the context that may have contributed to it.

You need to provide us a complete example that runs and reproduces the problem you are observing.

In your case, you should also tell us what environment you are using: a simple python script, and IDE, etc. If GTK has already been loaded this must be related to your environment.

To post code, please use triple back-ticks for proper formatting:

for x in range(100):
    print("hello world")

or upload your files as attachments.

My bad, I did not realise you could attach stuff to the post. I will provide more context.

Here is the script I was using. It is basically a copy of the beginning of the quick start.

from graph_tool.all import *

def test():
    g = Graph()
    v1 = g.add_vertex()
    v2 = g.add_vertex()

    e = g.add_edge(v1, v2)

    graph_draw(g, vertex_text=g.vertex_index)

if __name__ == "__main__":
    test()

Below you can find the command line output with the traceback. I wanted to add screenshot of the error message in VS Code (which is the IDE I am using), but I could only attach one image. If you need any more details please let me know.

Thanks for your quick reply!

What happens when you run the script directly, as:

python3 /home/matt/Repos/parallel-squares/test_graph.py

(BTW, It’s better to post text as text, not images. You can quote terminal outputs like this:

this is an output

)

When I run it directly I get the same error.

> Traceback (most recent call last):
  File "/home/matt/Repos/parallel-squares/test_graph.py", line 1, in <module>
    from graph_tool.all import *
  File "/usr/lib/python3.10/site-packages/graph_tool/all.py", line 34, in <module>
    from graph_tool.draw import *
  File "/usr/lib/python3.10/site-packages/graph_tool/draw/__init__.py", line 848, in <module>
    from . cairo_draw import graph_draw, cairo_draw, \
  File "/usr/lib/python3.10/site-packages/graph_tool/draw/cairo_draw.py", line 1494, in <module>
    gi.require_version('Gtk', '3.0')
  File "/usr/lib/python3.10/site-packages/gi/__init__.py", line 117, in require_version
    raise ValueError('Namespace %s is already loaded with version %s' %
ValueError: Namespace Gtk is already loaded with version 4.0

Do you know what matplotlib backend you are using?

After checking the matplotlib documentation I found out I was using GTK4 by default. After changing the script to configure it to use GTK3, the script ran fine. I have added the code below in case anybody else runs into this problem later.

Thanks a lot for your help :smile:

import matplotlib
matplotlib.use('gtk3agg')

from graph_tool.all import *

def test():
    g = Graph()
    v1 = g.add_vertex()
    v2 = g.add_vertex()

    e = g.add_edge(v1, v2)

    graph_draw(g, vertex_text=g.vertex_index)

if __name__ == "__main__":
    test()
1 Like

FYI, your version of graph-tool is quite old. I recommend updating!

I am afraid that this is the most recent version available from my package manager. If I run into any more trouble I will consider building myself. Thanks for the tip!

Consider filing a bug upstream in your distribution, or using conda.

1 Like