Ask Your Question
2

No 3d graphics with sage 9.8 using conda-forge

asked 2023-04-29 20:30:42 +0100

richardquint gravatar image

updated 2023-05-11 11:37:52 +0100

FrédéricC gravatar image

I have a problem with an installation of sage-9.8 using conda-forge on Ubuntu 23.04. Following the installation guide for a complete installation I can run sage successfully. 2d graphics work, the png viewer launches, but trying an example using plot3d, nothing happens---that is sage replies it has lanuched the viewer but neither the web browser nor the jmol applet launches.

(base) rquint@LunarBox:~$ mamba activate sage
(sage) rquint@LunarBox:~$ sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 9.8, Release Date: 2023-02-11 │
│ Using Python 3.10.10. Type "help()" for help. │
└────────────────────────────────────────────────────────────────────┘
sage: 2+3
5
sage: var('x y')
(x, y)
sage: plot3d(x*y^3, (-1,1), (-1,1))
Launched html viewer for Graphics3d Object
sage: plot3d(x*y^3, (-1,1), (-1,1), viewer="jmol")
Launched jmol viewer for Graphics3d Object
sage: plot(x^3*sin(x), (-pi,pi))
Launched png viewer for Graphics object consisting of 1 graphics primitive
sage: exit
(sage) rquint@LunarBox:~$ mamba deactivate
(base) rquint@LunarBox:~$

Is there something else to install? If so, what are the requisite commands? (Thanks @slelievre for how to include code blocks.)

edit retag flag offensive close merge delete

Comments

To display code blocks properly, indent them by four spaces.

slelievre gravatar imageslelievre ( 2023-05-03 21:45:28 +0100 )edit

The solutions using alternative settings for TMPDIR and DOT_SAGE or a non-snap browser have all worked with installations of sage-9.8 built from source. There's something else going on with my installation using conda-forge. the jmol viewer worked straight out of the box with the installation build from source, but it doesn't with the conda-forge install. I'll try again as soon as sage-10 is out, but for now I have wiped the conda-forge install and have gone back to building from source.

richardquint gravatar imagerichardquint ( 2023-05-18 19:13:39 +0100 )edit

Sorry, I forgot to address the jmol part of the question. I can also confirm it fails for me.

Even with TMPDIR set to ~/tmp, plotting with jmol fails for me in conda-installed Sage 9.8.

slelievre gravatar imageslelievre ( 2023-05-19 17:34:28 +0100 )edit

2 Answers

Sort by » oldest newest most voted
3

answered 2023-05-10 23:54:19 +0100

slelievre gravatar image

updated 2023-05-11 16:35:21 +0100

I can reproduce with

  • SageMath 9.8 from conda-forge in Ubuntu 22.04
  • Firefox installed as a "snap"

What happens is:

  • SageMath saves the image to some html file in /tmp then asks your browser to open it
  • Firefox installed as a snap is set not to open files in /tmp

Three ways around this (including the one suggested by @John Palmieri):

  • either reinstall Firefox not as a "snap", which might help, see:
  • or run Sage with the TMPDIR environment variable set to some directory inside your home directory
  • or, as a workaround, manually save 3d graphics to html file, then open obtained file in browser

Example.

If Firefox is installed using apt install firefox, it might have been installed as a "snap":

$ dpkg-query --list firefox
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version           Architecture Description
+++-==============-=================-============-==============================================
ii  firefox        1:1snap1-0ubuntu2 amd64        Transitional package - firefox -> firefox snap

$ snap list | grep firefox
firefox              112.0.2-1                   2605   latest/stable/…  mozilla**       -

Here is what happens in that situation.

Start Sage:

$ conda activate sage
$ sage
SageMath version 9.8, released 2023-02-11. Python 3.10.8.

Declare "symbolic ring" variables, define plot, and try to view it

sage: x, y = SR.var('x, y')
sage: p = plot3d(x*y^3, (-1, 1), (-1, 1))
sage: p

For me this launches a Firefox tab which tries to access a temporary file and complains:

File not found

Firefox can’t find the file at /tmp/tmp58e2me0a/tmp_68ciixtz.html.

  • Check the file name for capitalization or other typing errors.
  • Check to see if the file was moved, renamed or deleted.

The problem is that Firefox installed as a "snap" is set not to open files in /tmp.

Things work if Sage starts with TMPDIR set to a subdirectory of the user's home directory.

I created a tmp directory in my home directory:

$ mkdir -p $HOME/tmp

Then things work if I start Sage with this command:

$ TMPDIR=$HOME/tmp sage

or with these two commands:

$ export TMPDIR=$HOME/tmp
$ sage

The "export" command can be included in a file that is run each time a shell is started. For example,~/.bashrc if using bash, or ~/.zshrc if using zsh.

If Sage was started without setting TMPDIR, we can save the plot to an html file and open that file:

sage: p.save("myplot.html")
sage: !open myplot.html

That works well for me.

edit flag offensive delete link more
2

answered 2023-05-11 02:38:49 +0100

Would the solution at https://ask.sagemath.org/question/641... help? That is, set TMPDIR so that files are saved in a directory that Firefox can actually access?

edit flag offensive delete link more

Comments

Brilliant! That works!

slelievre gravatar imageslelievre ( 2023-05-11 11:11:43 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2023-04-29 20:30:42 +0100

Seen: 488 times

Last updated: May 11 '23