ERROR: ReadOnlyMemoryError() when doing a basic plot?

plotting
error

#1

Hi,

I’m installing fresh computers, and one of the things I’m installing is Julia. I have tried so far three computers, all using the same distribution (ArchLinux), and all have the same versions of everything as far as I can see, but in two of them I get a ReadOnlyMemoryError() when trying a basic plot. These are the versions and the error I get:

[angelv@kepa ~]$ pacman -Q python python-matplotlib julia
python 3.6.2-1
python-matplotlib 2.0.2-1
julia 2:0.6.0-3
[angelv@kepa ~]$ julia
               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: https://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.6.0 (2017-06-19 13:05 UTC)
 _/ |\__'_|_|_|\__'_|  |  
|__/                   |  x86_64-pc-linux-gnu

julia> Pkg.status("Plots")
 - Plots                         0.12.4

julia> Pkg.status("PyPlot")
 - PyPlot                        2.3.2

julia> using Plots

julia> backend()
Plots.PyPlotBackend()

julia> plot(sin)
Error showing value of type Plots.Plot{Plots.PyPlotBackend}:
ERROR: ReadOnlyMemoryError()

julia> 

The exact same versions of these packages in two computers give me the error, while in the third one the plot is created no problem. ¿Any suggestions on how to find out what is going on?

Thanks,
Ángel de Vicente


#2

What happens if you do the following?

julia> using PyPlot

julia> xx = linspace(-2, 2, 100)
-2.0:0.004004004004004004:2.0

julia> plot(xx, sin.(xx))

That way we could atleast know whether the problem is with the backend. Have you tried the same thing with other backends? For example GR or Plotly?


#3

Hi,

this is quite weird, but I get the same result consistently in both computers which give trouble (let’s call them p1 and p2): the first plot command raises the ReadOnlyMemoryError, the second one makes the plot OK. But remember that the same libraries and versions give no trouble in the other computer, let’s call it o1 (the only thing that it is obviously different between these computers is that the one not giving any trouble has only one core, while the other two are multi-core computers).

using GR instead of PyPlot creates the plot OK in two of the computers (o1 and p1), but couldn’t try in p2, it ends up timing out when Pkg.add(“GR”). I tried the command several times and this one happens to be on the fastest network, and if I do a git clone of GR from outside julia it takes only seconds. In p1 Pkg.add(“GR”) also took quite much longer than the same in o1, despite being in the same network. I don’t see how these things could be related, but it looks like Julia has some serious issues in p1 and p2, despite having the same versions of everything.

Really puzzled… Any hints?

[angelv@kepa ~]$ julia
               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: https://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.6.0 (2017-06-19 13:05 UTC)
 _/ |\__'_|_|_|\__'_|  |  
|__/                   |  x86_64-pc-linux-gnu

julia> using PyPlot

julia> x=collect(0:0.01:2*pi);

julia> plot(x,sin.(x))
ERROR: PyError (ccall(@pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, arg, C_NULL)) <class 'RuntimeError'>
RuntimeError('Julia exception: ReadOnlyMemoryError()',)
  File "/usr/lib/python3.6/site-packages/matplotlib/pyplot.py", line 3306, in plot
    ax = gca()
  File "/usr/lib/python3.6/site-packages/matplotlib/pyplot.py", line 950, in gca
    return gcf().gca(**kwargs)
  File "/usr/lib/python3.6/site-packages/matplotlib/pyplot.py", line 586, in gcf
    return figure()

Stacktrace:
 [1] pyerr_check at /home/angelv/.julia/v0.6/PyCall/src/exception.jl:56 [inlined]
 [2] pyerr_check at /home/angelv/.julia/v0.6/PyCall/src/exception.jl:61 [inlined]
 [3] macro expansion at /home/angelv/.julia/v0.6/PyCall/src/exception.jl:81 [inlined]
 [4] #_pycall#67(::Array{Any,1}, ::Function, ::PyCall.PyObject, ::Array{Float64,1}, ::Vararg{Array{Float64,1},N} where N) at /home/angelv/.julia/v0.6/PyCall/src/PyCall.jl:653
 [5] _pycall(::PyCall.PyObject, ::Array{Float64,1}, ::Vararg{Array{Float64,1},N} where N) at /home/angelv/.julia/v0.6/PyCall/src/PyCall.jl:641
 [6] #pycall#71(::Array{Any,1}, ::Function, ::PyCall.PyObject, ::Type{PyCall.PyAny}, ::Array{Float64,1}, ::Vararg{Array{Float64,1},N} where N) at /home/angelv/.julia/v0.6/PyCall/src/PyCall.jl:675
 [7] pycall(::PyCall.PyObject, ::Type{PyCall.PyAny}, ::Array{Float64,1}, ::Vararg{Array{Float64,1},N} where N) at /home/angelv/.julia/v0.6/PyCall/src/PyCall.jl:675
 [8] #plot#85(::Array{Any,1}, ::Function, ::Array{Float64,1}, ::Vararg{Array{Float64,1},N} where N) at /home/angelv/.julia/v0.6/PyPlot/src/PyPlot.jl:172
 [9] plot(::Array{Float64,1}, ::Vararg{Array{Float64,1},N} where N) at /home/angelv/.julia/v0.6/PyPlot/src/PyPlot.jl:169
 [10] macro expansion at ./REPL.jl:97 [inlined]
 [11] (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:73

julia> plot(x,sin.(x))
1-element Array{PyCall.PyObject,1}:
 PyObject <matplotlib.lines.Line2D object at 0x7f87a83c7a58>

julia> 


#4

GR comes bundled with binaries for lots of different operating systems, when you call Pkg.add("GR") it downloads the binaries. You could check their repo to see if p1 is compatible with the binaries. What happens if you use p1 or p2 and try using matplotlib from python? That way we could see whether or not the problem is in PyPlot.jl or matplotlib.


#5

Hi,

I will try GR again in the computer that was giving trouble, but it was stuck at the git cloning step, so I don’t know if it will work yet, but I guess that is a separate problem.

As per matplotlib in python in p1 and p2, no problem with either, so it certainly looks like PyPlot is the culprit…


#6

Today I upgraded all packages in ArchLinux and all packages in Julia, but I still have the same problem.

The first time I issue the plot command I get the ReadOnlyMemoryError(), the second time I get a matplotlib window but without any content, all black, the third time I call plot then I get the plot, and after that all calls to plot work OK.


#7

Whoops, I only just saw this now (sorry). The only other troubleshooting advice that I can give is to try see if you can get PyCall to work. That way you would have a really strong case for blaming PyPlot. Try the following:

using PyCall

@pyimport matplotlib.pyplot as plt
x = linspace(0,2*pi,1000); y = sin(3*x + 4*cos(2*x));
plt.plot(x, y, color="red", linewidth=2.0, linestyle="--")
plt.show()

(Or you could try any other eamples on their README)

The only other general advice that I have would be to hope that somebody more experienced comes to this thread or that you open an issue on PyPlot. In the meantime, it sounds like you have GR working on two computers, so that should hopefully help you until we can fix PyPlot.

Also, if you just click the reply button on my comment, then I will get a notification which will hopefully mean that I wont take a month to respond :laughing:


#8

Hi,

thanks for the reply. There is an issue on PyPlot about this (https://github.com/JuliaPy/PyPlot.jl/issues/291) but it seems that is not assigned to anyone yet, perhaps this is not happening to many people. Don’t know.

I was actually trying what you suggest just today and I put the results in that thread. To summarize:

  • The library versions I have:
    python 3.6.3-1
    python-matplotlib 2.1.0-1
    julia 2:0.6.1-1
    qt5-3d 5.9.2-1
    qt5-datavis3d 5.9.2-1
    qt5-x11extras 5.9.2-1
    Plots 0.13.1
    PyPlot 2.3.2

  • If I create a basic plot from within Python there is no issue at all.

  • If I try to create a plot from Julia using Plots, I only manage to get a working plot at the third attempt (OK after that)

  • If I try to use PyCall as per your suggestion I first get the ReadOnlyMemoryError(), then a blank matplotlib window, and then nothing… (see below)

julia> using PyCall
julia> PyCall.python
"python"

julia> @pyimport matplotlib.pyplot as plt
julia> x = linspace(0,2*pi,100); y = sin.(x);
julia> plt.plot(x, y)
1-element Array{PyCall.PyObject,1}:
PyObject <matplotlib.lines.Line2D object at 0x7f9570f24e48>

julia> plt.show()
ERROR: ReadOnlyMemoryError()
Stacktrace:
[1] macro expansion at /home/angelv/.julia/v0.6/PyCall/src/exception.jl:78 [inlined]
[2] #_pycall#67(::Array{Any,1}, ::Function, ::PyCall.PyObject) at /home/angelv/.julia/v0.6/PyCall/src/PyCall.jl:653
[3] #pycall#71(::Array{Any,1}, ::Function, ::PyCall.PyObject, ::Type{PyCall.PyAny}) at /home/angelv/.julia/v0.6/PyCall/src/PyCall.jl:675
[4] #call#72 at /home/angelv/.julia/v0.6/PyCall/src/PyCall.jl:678 [inlined]
[5] (::PyCall.PyObject)() at /home/angelv/.julia/v0.6/PyCall/src/PyCall.jl:678
[6] macro expansion at ./REPL.jl:97 [inlined]
[7] (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:73

julia> plt.show()
julia> plt.show()
type or paste code here

The second call to plt.show() creates a matplotlib window but no plot is seen. I close the window and issue a third plt.show() and then the third call returns immediately but does not create any plot either.


#9

That issue looks like your best bet for getting this to work. I wouldn’t expect anyone to be assigned to the issue because it seems like nobody knows precisely what is causing the problem. Sorry that I couldn’t be more useful, but I am fairly sure that you will be able to resolve things through that issue.


#10

Thanks. I fill follow the issue in GitHub and see if some solution comes up. If it does I will update this thread in case it can be of interest to somebody in the future.

Cheers,