# Julia crashes when using ImageView together with PyPlot

**URL:** <https://discourse.julialang.org/t/julia-crashes-when-using-imageview-together-with-pyplot/63071>\
**Category:** General Usage\
**Created:** [June 17, 2021, 7:38am UTC](https://discourse.julialang.org/t/julia-crashes-when-using-imageview-together-with-pyplot/63071 "2021-06-17T07:38:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xor0110](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xor0110/32/7926_2.png) [@xor0110](https://discourse.julialang.org/u/xor0110)\
**Post date:** [June 17, 2021, 7:38am UTC](https://discourse.julialang.org/t/julia-crashes-when-using-imageview-together-with-pyplot/63071/1 "2021-06-17T07:38:27Z")

</div>

In one of my machines, it has become impossible for me to use PyPlot and ImageView at the same time, Julia crashes with a message like:

```julia
XmbTextListToTextProperty result code -2
XmbTextListToTextProperty result code -2
XmbTextListToTextProperty result code -2

julia> imshow(ii)

signal (11): Segmentation fault
in expression starting at REPL[9]:1
_PyErr_Restore at /home/nicolau/.julia/conda/3/lib/libpython3.8.so.1.0 (unknown line)
PyDict_GetItem at /home/nicolau/.julia/conda/3/lib/libpython3.8.so.1.0 (unknown line)

```

Is this an issue I should bring up to the ImageView, PyPlot, PyCall or Julia projects?.. And are there any workarounds I can try?

---

<div class="post-metadata">

**Author:** ![mdhe1248](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mdhe1248/32/30870_2.png) [@mdhe1248](https://discourse.julialang.org/u/mdhe1248)\
**Post date:** [April 20, 2023, 2:13am UTC](https://discourse.julialang.org/t/julia-crashes-when-using-imageview-together-with-pyplot/63071/2 "2023-04-20T02:13:37Z")

</div>

It has been long time, but this or similar error was solved by this:

> <https://github.com/JuliaGraphics/Gtk.jl/issues/193>
>
> I'm not able to use both PyPlot and Gtk at the same time. I get different probl…ems depending on which I import first:
> 
> \`\`\`
> \_
> \_ \_ \_(\_)\_ | A fresh approach to technical computing
> (\_) | (\_) (\_) | Documentation: http://docs.julialang.org
> \_ \_ \_| |\_ \_\_ \_ | Type "?help" for help.
> | | | | | | |/ \_\` | |
> | | |\_| | | | (\_| | | Version 0.4.0 (2015-10-08 06:20 UTC)
> \_/ |\\\_\_'\_|\_|\_|\\\_\_'\_| |  
> |\_\_/ | x86\_64-redhat-linux
> 
> julia\> using Gtk
> 
> julia\> using PyPlot
> /usr/lib64/python2.7/site-packages/gtk-2.0/gtk/\_\_init\_\_.py:40: Warning: g\_boxed\_type\_register\_static: assertion 'g\_type\_from\_name (name) == 0' failed
> from gtk import \_gtk
> /usr/lib64/python2.7/site-packages/gtk-2.0/gtk/\_\_init\_\_.py:40: Warning: g\_type\_set\_qdata: assertion 'node != NULL' failed
> from gtk import \_gtk
> /usr/lib64/python2.7/site-packages/gtk-2.0/gtk/\_\_init\_\_.py:40: Warning: cannot register existing type 'GtkWidget'
> from gtk import \_gtk
> /usr/lib64/python2.7/site-packages/gtk-2.0/gtk/\_\_init\_\_.py:40: Warning: g\_type\_add\_interface\_static: assertion 'G\_TYPE\_IS\_INSTANTIATABLE (instance\_type)' failed
> from gtk import \_gtk
> /usr/lib64/python2.7/site-packages/gtk-2.0/gtk/\_\_init\_\_.py:40: Warning: cannot register existing type 'GtkBuildable'
> from gtk import \_gtk
> /usr/lib64/python2.7/site-packages/gtk-2.0/gtk/\_\_init\_\_.py:40: Warning: g\_type\_interface\_add\_prerequisite: assertion 'G\_TYPE\_IS\_INTERFACE (interface\_type)' failed
> from gtk import \_gtk
> /usr/lib64/python2.7/site-packages/gtk-2.0/gtk/\_\_init\_\_.py:40: Warning: g\_once\_init\_leave: assertion 'result != 0' failed
> from gtk import \_gtk
> /usr/lib64/python2.7/site-packages/gtk-2.0/gtk/\_\_init\_\_.py:40: Warning: g\_type\_register\_static: assertion 'parent\_type \> 0' failed
> from gtk import \_gtk
> ^C/usr/lib64/python2.7/site-packages/matplotlib/\_\_init\_\_.py:1005: UserWarning: This call to matplotlib.use() has no effect
> because the the backend has already been chosen;
> matplotlib.use() must be called \*before\* pylab, matplotlib.pyplot,
> or matplotlib.backends is imported for the first time.
> 
> warnings.warn(\_use\_error\_msg)
> ERROR: InitError: PyError (:PyImport\_ImportModule) \<type 'exceptions.AttributeError'\>
> AttributeError("'module' object has no attribute 'gdk'",)
> File "/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py", line 97, in \<module\>
> \_backend\_mod, new\_figure\_manager, draw\_if\_interactive, \_show = pylab\_setup()
> File "/usr/lib64/python2.7/site-packages/matplotlib/backends/\_\_init\_\_.py", line 25, in pylab\_setup
> globals(),locals(),\[backend\_name\])
> File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend\_gtkagg.py", line 10, in \<module\>
> from matplotlib.backends.backend\_gtk import gtk, FigureManagerGTK, FigureCanvasGTK,\\
> File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend\_gtk.py", line 13, in \<module\>
> import gtk; gdk = gtk.gdk
> 
> \[inlined code\] from /home/tom/.julia/v0.4/PyCall/src/exception.jl:81
> in pyimport at /home/tom/.julia/v0.4/PyCall/src/PyCall.jl:79
> in \_\_init\_\_ at /home/tom/.julia/v0.4/PyPlot/src/PyPlot.jl:250
> in \_require\_from\_serialized at loading.jl:84
> in \_require\_from\_serialized at ./loading.jl:109
> in require at ./loading.jl:219
> during initialization of module PyPlot
> 
> julia\> 
> \[tom@tomoffice Plots\]$ julia
> \_
> \_ \_ \_(\_)\_ | A fresh approach to technical computing
> (\_) | (\_) (\_) | Documentation: http://docs.julialang.org
> \_ \_ \_| |\_ \_\_ \_ | Type "?help" for help.
> | | | | | | |/ \_\` | |
> | | |\_| | | | (\_| | | Version 0.4.0 (2015-10-08 06:20 UTC)
> \_/ |\\\_\_'\_|\_|\_|\\\_\_'\_| |  
> |\_\_/ | x86\_64-redhat-linux
> 
> julia\> using PyPlot
> 
> julia\> using Gtk
> sys:1: Warning: cannot register existing type 'GdkDisplayManager'
> sys:1: Warning: g\_once\_init\_leave: assertion 'result != 0' failed
> sys:1: Warning: g\_type\_register\_static: assertion 'parent\_type \> 0' failed
> sys:1: Warning: g\_object\_new: assertion 'G\_TYPE\_IS\_OBJECT (object\_type)' failed
> 
> 
> ^CERROR: InitError: InterruptException:
> in anonymous at /home/tom/.julia/v0.4/Gtk/src/events.jl:11
> in call at /home/tom/.julia/v0.4/Gtk/src/GLib/gerror.jl:13
> in \_\_init\_\_ at /home/tom/.julia/v0.4/Gtk/src/events.jl:10
> in \_require\_from\_serialized at loading.jl:84
> in \_require\_from\_serialized at ./loading.jl:109
> in require at ./loading.jl:219
> during initialization of module Gtk
> 
> julia\> 
> \`\`\`
> 
> cc: @stevengj

Basically, add `backend: WebAgg` in your matplotlibrc.  
matplotlibrc is located somewhere like this:  
`somefolder/lib/python3.9/site-packages/matplotlib/mpl-data/matplotlibrc`

At some point, I didn’t have to add backend: WebAgg and pyplot and imageview both worked fine. However, I noticed that pyplot elicited some fatal errors after some work with multithreading. After adding the backend magic, it does not give any trouble.
