Error with Julia 1.0 + Plots with GR and PyPlot + Conda

Hi,

I’m using Julia 1.0 and is trying to use Plots for my plotting. For PyCall, I’m using system conda installation.

julia> versioninfo()
Julia Version 1.0.0
Commit 5d4eaca0c9 (2018-08-08 20:58 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, skylake)

(v1.0) pkg> status
    Status `~/.julia/environments/v1.0/Project.toml`
  [31c24e10] Distributions v0.16.2
  [28b8d3ca] GR v0.32.3
  [7073ff75] IJulia v1.9.3
  [91a5bcdd] Plots v0.19.3
  [d330b81b] PyPlot v2.6.1

(v1.0) pkg> 

Now, if I try to use Plots (with GR being the default backend, I get this error:

julia> using Plots

julia> plot( cumsum(rand(10)) )
/home/vish/.julia/packages/GR/fnyt8/src/../deps/gr/bin/gksqt: error while loading shared libraries: libQtGui.so.4: cannot open shared object file: No such file or directory
connect: Connection refused
GKS: can't connect to GKS socket application
Did you start 'gksqt'?

GKS: Open failed in routine OPEN_WS
GKS: GKS not in proper state. GKS must be either in the state WSOP or WSAC in routine ACTIVATE_WS
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine FILLAREA
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine FILLAREA
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine TEXT
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine TEXT
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine TEXT
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine TEXT
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine TEXT
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine TEXT
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine TEXT
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine TEXT
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine TEXT
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE

Seems like I’m missing QT libraries. I would expect it will be installed if I install Plots by default.
So, now, which package should I install now? I’m in 64-bit ubuntu.

Interesting things happen if I try to switch the backend to PyPlot. I already have PyPlot directly installed in my julia (Project.toml shows it). Now if I try to swicth the backend using pyplot(), I get the following error:

julia> pyplot()
sys:1: UserWarning: 
This call to matplotlib.use() has no effect because the backend has already
been chosen; matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.

The backend was *originally* set to 'Qt5Agg' by the following code:
  File "/home/vish/.julia/packages/Conda/m7vem/deps/usr/lib/python3.7/site-packages/matplotlib/backends/__init__.py", line 16, in <module>
    line for line in traceback.format_stack()


ERROR: InitError: PyError (PyImport_ImportModule

The Python package matplotlib.pyplot could not be found by pyimport. Usually this means
that you did not install matplotlib.pyplot in the Python version being used by PyCall.

PyCall is currently configured to use the Julia-specific Python distribution
installed by the Conda.jl package.  To install the matplotlib.pyplot module, you can
use `pyimport_conda("matplotlib.pyplot", PKG)`, where PKG is the Anaconda
package the contains the module matplotlib.pyplot, or alternatively you can use the
Conda package directly (via `using Conda` followed by `Conda.add` etcetera).

Alternatively, if you want to use a different Python distribution on your
system, such as a system-wide Python (as opposed to the Julia-specific Python),
you can re-configure PyCall with that Python.   As explained in the PyCall
documentation, set ENV["PYTHON"] to the path/name of the python executable
you want to use, run Pkg.build("PyCall"), and re-launch Julia.

) <class 'ImportError'>
ImportError('/home/vish/.julia/packages/Conda/m7vem/deps/usr/lib/python3.7/site-packages/PyQt5/../../../libxcb-dri3.so.0: undefined symbol: xcb_send_request_with_fds')
  File "/home/vish/.julia/packages/Conda/m7vem/deps/usr/lib/python3.7/site-packages/matplotlib/pyplot.py", line 115, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/home/vish/.julia/packages/Conda/m7vem/deps/usr/lib/python3.7/site-packages/matplotlib/backends/__init__.py", line 62, in pylab_setup
    [backend_name], 0)
  File "/home/vish/.julia/packages/Conda/m7vem/deps/usr/lib/python3.7/site-packages/matplotlib/backends/backend_qt5agg.py", line 15, in <module>
    from .backend_qt5 import (
  File "/home/vish/.julia/packages/Conda/m7vem/deps/usr/lib/python3.7/site-packages/matplotlib/backends/backend_qt5.py", line 19, in <module>
    import matplotlib.backends.qt_editor.figureoptions as figureoptions
  File "/home/vish/.julia/packages/Conda/m7vem/deps/usr/lib/python3.7/site-packages/matplotlib/backends/qt_editor/figureoptions.py", line 20, in <module>
    import matplotlib.backends.qt_editor.formlayout as formlayout
  File "/home/vish/.julia/packages/Conda/m7vem/deps/usr/lib/python3.7/site-packages/matplotlib/backends/qt_editor/formlayout.py", line 54, in <module>
    from matplotlib.backends.qt_compat import QtGui, QtWidgets, QtCore
  File "/home/vish/.julia/packages/Conda/m7vem/deps/usr/lib/python3.7/site-packages/matplotlib/backends/qt_compat.py", line 135, in <module>
    _setup_pyqt5()
  File "/home/vish/.julia/packages/Conda/m7vem/deps/usr/lib/python3.7/site-packages/matplotlib/backends/qt_compat.py", line 69, in _setup_pyqt5
    from PyQt5 import QtCore, QtGui, QtWidgets

Stacktrace:
 [1] pyimport(::String) at /home/vish/.julia/packages/PyCall/akNFy/src/PyCall.jl:479
 [2] __init__() at /home/vish/.julia/packages/PyPlot/Sx8Lp/src/init.jl:187
 [3] _include_from_serialized(::String, ::Array{Any,1}) at ./loading.jl:627
 [4] macro expansion at ./logging.jl:312 [inlined]
 [5] _require_search_from_serialized(::Base.PkgId, ::String) at ./loading.jl:698
 [6] _require(::Base.PkgId) at ./loading.jl:931
 [7] require(::Base.PkgId) at ./loading.jl:852
 [8] macro expansion at ./logging.jl:311 [inlined]
 [9] require(::Module, ::Symbol) at ./loading.jl:834
 [10] top-level scope at /home/vish/.julia/packages/Plots/ex9On/src/backends.jl:389
 [11] eval at ./boot.jl:319 [inlined]
 [12] _initialize_backend(::Plots.PyPlotBackend) at /home/vish/.julia/packages/Plots/ex9On/src/backends.jl:388
 [13] backend(::Plots.PyPlotBackend) at /home/vish/.julia/packages/Plots/ex9On/src/backends.jl:196
 [14] backend(::Symbol) at /home/vish/.julia/packages/Plots/ex9On/src/backends.jl:209
 [15] pyplot() at /home/vish/.julia/packages/Plots/ex9On/src/backends.jl:29
 [16] top-level scope at none:0
during initialization of module PyPlot

I’m able to use PyPlot directly. This error shows up only if I try to use PyPlot as my Plots backend.
After restarting julia, I can run PyPlot without any errors

julia> using PyPlot

julia> plot( cumsum(rand(10)) )
QApplication: invalid style override passed, ignoring it.
1-element Array{PyCall.PyObject,1}:
 PyObject <matplotlib.lines.Line2D object at 0x7f526009e6d8>

So how can I fix Plots installation to use GR and PyPlot (or atleast GR) in this case?

For GR, you will have to install the Qt5 run-time, as described on http://gr-framework.org/julia.html :

apt install libxt6 libxrender1 libgl1-mesa-glx libqt5widgets5
1 Like

I already have them installed. This GR is specifically asking for an older version. The error says /home/vish/.julia/packages/GR/fnyt8/src/../deps/gr/bin/gksqt: error while loading shared libraries: libQtGui.so.4: cannot open shared object file: No such file or directory.

I don’t have corresponding packages for libQt4 in my repository. :confused:

The current version of GR (for Ubuntu) is linked against Qt5. Do you really have the correct run-time installed?

Please try:

import Pkg
ENV["GRDIR"]=""
Pkg.build("GR")

Yeah. Even with that, the problem persists.

I found the reason:
While setting up GR.jl, when julia runs deps/build.jl, it downloads generic GR binary for linux (https://gr-framework.org/downloads/gr-0.32.0-Linux-x86_64.tar.gz) which is linked to QT4. I tried manually downloading the generic zip and if I run gksqt, the error comes:

vish@eliteone:~/Downloads/gr/bin$ ./gksqt 
./gksqt: error while loading shared libraries: libQtGui.so.4: cannot open shared object file: No such file or directory
vish@eliteone:~/Downloads/gr/bin$ 

But if I replace it with Ubuntu specific binary (https://gr-framework.org/downloads/gr-0.32.0-Ubuntu-x86_64.tar.gz), I’m able to successfully start gksqt.

So it seems like a GR issue than GR.jl issue. The official binaries are built with QT4. I don’t know is there any specific reason for this. Should I report this as an issue in main GR repository?

For the moment, the solution is to download and copy gr files manually to the julia package location.

Now to the core reason of why this happened - why julia downloaded generic binary rather than the specific ubuntu binary. I’m actually in ElementaryOS which is a Ubuntu derivative. So when julia ran deps.jl, it did not trigger ubuntu specific part and fell back to linux generic.
Easy will be to fix the deps/build.jl to include elementaryOS also as a case.

What’s the output of cat /etc/os-release ?

vish@eliteone:~/Downloads/gr/bin$ cat /etc/os-release
NAME="elementary OS"
VERSION="0.4.1 Loki"
ID="elementary"
ID_LIKE=ubuntu
PRETTY_NAME="elementary OS 0.4.1 Loki"
VERSION_ID="0.4.1"
HOME_URL="http://elementary.io/"
SUPPORT_URL="http://elementary.io/support/"
BUG_REPORT_URL="https://github.com/elementary/"
VERSION_CODENAME=loki
UBUNTU_CODENAME=loki

I just opened a pull request to fix this: https://github.com/jheinen/GR.jl/pull/141