Ask Your Question

init.sage doesn't work for the notebook server?

asked 2016-02-09 21:15:20 +0200

Eugene gravatar image

updated 2023-01-09 23:59:39 +0200

tmonteil gravatar image


I have the same problem as in Is there a way to prefix all sage code in order to include a custom module?, but the init.sage appears not to work with notebook's worksheet. Here is what I have:

$ cat ~/.sage/init.sage 
import numpy as np

then inside Sage I have:

$ ./sage 
sage: np
<module 'numpy' from ....>

But then I run notebook() and create a new worksheet, inside that worksheet session:

NameError: name 'np' is not defined

So I assume that the script was not executed for the worksheet.

Is there a way to create sage.init but for the worksheets?

edit retag flag offensive close merge delete


P.S. I edited question to make it simpler. I that may be a bug?

Eugene gravatar imageEugene ( 2016-02-11 21:29:43 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2016-02-11 21:44:06 +0200

tmonteil gravatar image

updated 2016-02-11 21:51:59 +0200

I guess this is a bug, since the documentation do not restrict the use of init.sage to the command line. Thanks for reporting, it is now trac ticket 20042. Note that it works on the jupyter notebook, only the Sage notebook is affected.

A workaround could be to add the following line at the beginning of your worksheet:

import os ; load(os.environ['SAGE_STARTUP_FILE'])
edit flag offensive delete link more


Thank you! I suppose the question is answered and I should monitor track ticket from now on.

Eugene gravatar imageEugene ( 2016-02-13 22:09:27 +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

1 follower


Asked: 2016-02-09 21:15:20 +0200

Seen: 375 times

Last updated: Feb 11 '16