Ask Your Question

Plot not working

asked 2020-04-26 17:37:16 +0200

ZeJibe gravatar image

updated 2020-04-27 14:32:25 +0200

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 15:40:31 +0200 )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 15:42:39 +0200 )edit

1 Answer

Sort by » oldest newest most voted

answered 2020-04-27 15:31:43 +0200

Sébastien gravatar image

updated 2020-04-27 17:01:28 +0200

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 15:51:01 +0200 )edit

Thanks a ton - this works indeed!

ZeJibe gravatar imageZeJibe ( 2020-04-28 12:21:55 +0200 )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 17:37:16 +0200

Seen: 1,321 times

Last updated: Apr 27 '20