Ask Your Question

Plot not working

asked 2020-04-26 10:37:16 -0500

ZeJibe gravatar image

updated 2020-04-27 07:32:25 -0500

I am new to SageMath and am following the examples from the basic tutorials. The following command does not work:

plot3d(x^2 + y^2, (x,-2,2), (y,-2,2))

The error message is

sh: -c: line 0: syntax error near unexpected token `(' 
sh: -c: line 0:`sage-open/Users/xxx/.sage/temp/MacBook-Pro-(6)/1333/tmp_smrlkile.html 2>/dev/null 1>/dev/null &'

Browsing to the temp directory, I do find the .html file and can open it (it displays the right graph). It seems the viewer cannot open it from the terminal application of SageMath. Is this due to the presence of parentheses in the auto-generated temporary directory? If so, how can I changed it?

edit retag flag offensive close merge delete


Welcome to Ask Sage! Thank you for your question!

slelievre gravatar imageslelievre ( 2020-04-27 08:40:31 -0500 )edit

The operating system seems to be macOS, but what version of macOS? What version of Sage? How was it installed: via Conda, via Homebrew, from a binary downloaded from the SageMath website, or built from source? Are you using Sage in the terminal, in a Jupyter notebook, or in any other way?

slelievre gravatar imageslelievre ( 2020-04-27 08:42:39 -0500 )edit

1 answer

Sort by » oldest newest most voted

answered 2020-04-27 08:31:43 -0500

Sébastien gravatar image

updated 2020-04-27 10:01:28 -0500

I think it does not like the fact that your computer is called MacBook-Pro-(6) where some characters are parenthesis. In SageMath, the name of the computer (hostname) is used to construct the path of a temporary file:

sage: tmp_filename(ext='.html')

The error occurs when it tries to open that filename which contains parenthesis. If you can change the HOSTNAME by removing the parenthesis, it should fix the issue. Also, I don't know, maybe this is a bug that could be fixed in the SageMath library.

Trying to find a workaround does not seem easy as I am not able to save the graphics to the local folder which would not contain parenthesis in your case:

sage: y=var('y'); G = plot3d(x^2 + y^2, (x,-2,2), (y,-2,2))
Traceback (most recent call last):
ValueError: filetype .html not supported by save()
edit flag offensive delete link more



Excellent analysis.

In that case, before launching Sage, change the hostname.

So depending on whether you want to use the REPL, or Jupyter Notebook, or Jupyter Lab:

HOSTNAME=MacBookPro sage

HOSTNAME=MacBookPro sage -n jupyter

HOSTNAME=MacBookPro sage -n jupyterlab

To fix more permanently, either set the HOSTNAME to something without parentheses in ~/.bash_profile or ~/.zsh_profile, or define an alias there such as

alias sage="HOSTNAME=MacBookPro sage"
slelievre gravatar imageslelievre ( 2020-04-27 08:51:01 -0500 )edit

Thanks a ton - this works indeed!

ZeJibe gravatar imageZeJibe ( 2020-04-28 05:21:55 -0500 )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


Asked: 2020-04-26 10:37:16 -0500

Seen: 47 times

Last updated: Apr 27