Closed fusion809 closed 5 years ago
nix-env -i python2.7-matplotlib-2.2.3 sage-8.4
Installing a Python library like this is not supported. I can't tell you how it is supposed to work with sage though.
I didn't actually run that command, I only ran nix-env -i sage
, I included the python2.7-matplotlib-2.2.3
(which FYI was already installed on my system when I decided to start plotting with Matplotlib) in case it wasn't drawn in by SageMath and was only on my system due to the packages I have installed in the past. I think this is, in fact, a Matplotlib issue and not a SageMath one as I have also not been able to get Matplotlib to plot plots handed to it by Julia, per #50415.
if the default backend is gtk based: see this article in the wiki: https://nixos.wiki/wiki/Python#Gnome
You probably need to run sage inside nix-shell -p gobjectIntrospection gtk3
For other backends, I don't know.
Well I'll be ....ed, @symphorien your comment has saved my Nix-based math experience! Matplotlib is now working, I merely needed to run:
nix-shell -p gobjectIntrospection gtk3 'python36.withPackages(ps : with ps; [ matplotlib pygobject3 ipython ])'
and then run Julia in the resulting prompt to get its PyPlot module to work (which relies on Matplotlib), and for SageMath I'm not sure what fixed it, but I think it was:
nix-shell -p gobjectIntrospection gtk3 'python2.withPackages (ps: with ps; [ pygobject3 ])' --run "python -c \"import pygtkcompat; pygtkcompat.enable_gtk(version='3.0')\""
sage does have matplotlib
as a dependency, so you don't need to pull it in explicitly.
Thank you for reporting this. Relying on the user to somehow find out they have to nix-shell -p gobjectIntrospection gtk3
is very bad UX, so I do consider this a bug. @symphorien do you know if there is an easy way to fix that in the matplotlib package without user interaction?
@fusion809 just FYI in case you planned to invest much time in it, the sage notebook is deprecated.
My understanding is that there are two problems here:
wrapGappsHook
for example.@timokau Yeah I know it is deprecated, but from what I've read it is not going to be removed, simply not further developed. Thanks for the FYI in case I didn't know though.
Shouldn't it be possible to patch matplotlib
to set those environment variables itself on import? Not sure if there is some code that always runs on import though, does python always run the top-level python file even if I do from matplotlib import y
?
@fusion809 It will be removed. See https://groups.google.com/forum/#!topic/sage-devel/UgVUEFwL_D4 for details.
@timokau Thanks I think I read: https://trac.sagemath.org/ticket/25837 and focused on the parts where they said until the Jupyter notebook finally obtains all the features of the old SageMath notebook, the traditional notebook will not be removed. Must have misread that originally, thanks for bringing that sad fact to my attention. I guess it is time for me to develop Jupyter knowledge.
Guessing that question of yours isn't directed at me? Nix is a programming knowledge I know very little about, and the Nix package manager I only know the basics of how to use it.
Yes importing a python file will execute it. In libraries they usually just define stuff, but they can set the environment. cc @jtojnar who wrote wrapGappHook
: would it be sensible to "inline" the wrapper inside matplotlib to ensure gtk can be used by all dependent packages ?
@fusion809 that is right, it won't be removed until its a complete replacement. There is an increasing push in that direction currently though. One of the reasons is that nobody wants to port the sage notebook to python3 and python3 compatibility is planned soon-ish (given the deadline).
Reopening because the matplotlib issue is still around, even though there is a workaround.
If you want to get rid of the wrapGAppsHook requirement, you will need to do the same thing GNOME extensions do: prepend Gtk
and the typelibs it depends on (Cairo
, Pango
…) to GIRepository
search path: https://github.com/NixOS/nixpkgs/blob/master/pkgs/desktops/gnome-3/core/gnome-shell-extensions/fix_gmenu.patch
It needs to be done in this file: https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/backends/_gtk3_compat.py
If the libraries also call file chooser dialogue, it will be even harder and will require patching GTK with GSettings schema paths.
In https://gitlab.gnome.org/GNOME/gtk/blob/master/gtk/gtkfilechooserutils.c#L458
sage apparently by default does not show any interactive plots. It instead expects you to write plots into a file. You can however select a different backend using %matplotlib <backend>
.
I've just pushed #51032 to add tkinter (%matplotlib tk
). Within the now working jupyter notebook %matplotlib inline
works without issues. Not sure why it displayed plots on the "default ubuntu tarball", but I tried it in a sage build from source and it doesn't display anything by default.
Issue description
Under SageMath 8.4 (@timokau) I have noticed that my plots in Matplotlib are failing to launch. Here is what I am running in SageMath (doesn't seem to matter if I run it in the notebook interface, or from the command-line):
and while the output I see at the command-line:
matches what I see when SageMath is running properly, no plot window appears. When I run SageMath 8.4 from its official Ubuntu 18.04 tarball, I do not experience this issue on openSUSE Tumbleweed (oddly this tarball works fine on Tumbleweed). The plot window appears, and shows the expected Lorenz attractor in 3D wireframe format:
Steps to reproduce
On openSUSE Tumbleweed install Matplotlib 2.2.3 on Python 2.7 and SageMath 8.4 with:
(after installing Nix with the installer script at https://nixos.org/nix/install and setting up PATH to point to $HOME/.nix-profile/bin), then run:
and under SageMath, either its notebook interface (started by running
notebook()
in the prompt that starts after runningsage
) or right at thesage:
prompt, run:Technical details
Thanks for your time, Brenton