ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 13 Feb 2016 15:09:27 -0600init.sage doesn't work for the notebook server?http://ask.sagemath.org/question/32513/initsage-doesnt-work-for-the-notebook-server/Hello!
I have the same problem as in [Is there a way to prefix all sage code in order to include a custom module?](http://ask.sagemath.org/question/8407/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:
np
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?Tue, 09 Feb 2016 14:15:20 -0600http://ask.sagemath.org/question/32513/initsage-doesnt-work-for-the-notebook-server/Comment by Eugene for <p>Hello!</p>
<p>I have the same problem as in <a href="http://ask.sagemath.org/question/8407/is-there-a-way-to-prefix-all-sage-code-in-order-to-include-a-custom-module/">Is there a way to prefix all sage code in order to include a custom module?</a>, but the init.sage appears not to work with notebook's worksheet. Here is what I have:</p>
<pre><code>$ cat ~/.sage/init.sage
import numpy as np
</code></pre>
<p>then inside Sage I have:</p>
<pre><code>$ ./sage
sage: np
<module 'numpy' from ....>
</code></pre>
<p>But then I run notebook() and create a new worksheet, inside that worksheet session:</p>
<pre><code>np
NameError: name 'np' is not defined
</code></pre>
<p>So I assume that <strong>the script was not executed for the worksheet</strong>.</p>
<p>Is there a way to create sage.init but for the worksheets?</p>
http://ask.sagemath.org/question/32513/initsage-doesnt-work-for-the-notebook-server/?comment=32539#post-id-32539P.S. I edited question to make it simpler. I that may be a bug?Thu, 11 Feb 2016 14:29:43 -0600http://ask.sagemath.org/question/32513/initsage-doesnt-work-for-the-notebook-server/?comment=32539#post-id-32539Answer by tmonteil for <p>Hello!</p>
<p>I have the same problem as in <a href="http://ask.sagemath.org/question/8407/is-there-a-way-to-prefix-all-sage-code-in-order-to-include-a-custom-module/">Is there a way to prefix all sage code in order to include a custom module?</a>, but the init.sage appears not to work with notebook's worksheet. Here is what I have:</p>
<pre><code>$ cat ~/.sage/init.sage
import numpy as np
</code></pre>
<p>then inside Sage I have:</p>
<pre><code>$ ./sage
sage: np
<module 'numpy' from ....>
</code></pre>
<p>But then I run notebook() and create a new worksheet, inside that worksheet session:</p>
<pre><code>np
NameError: name 'np' is not defined
</code></pre>
<p>So I assume that <strong>the script was not executed for the worksheet</strong>.</p>
<p>Is there a way to create sage.init but for the worksheets?</p>
http://ask.sagemath.org/question/32513/initsage-doesnt-work-for-the-notebook-server/?answer=32542#post-id-32542I 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](https://trac.sagemath.org/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'])
Thu, 11 Feb 2016 14:44:06 -0600http://ask.sagemath.org/question/32513/initsage-doesnt-work-for-the-notebook-server/?answer=32542#post-id-32542Comment by Eugene for <p>I guess this is a bug, since the documentation do not restrict the use of <code>init.sage</code> to the command line. Thanks for reporting, it is now <a href="https://trac.sagemath.org/ticket/20042">trac ticket 20042</a>. Note that it works on the jupyter notebook, only the Sage notebook is affected.</p>
<p>A workaround could be to add the following line at the beginning of your worksheet:</p>
<pre><code>import os ; load(os.environ['SAGE_STARTUP_FILE'])
</code></pre>
http://ask.sagemath.org/question/32513/initsage-doesnt-work-for-the-notebook-server/?comment=32560#post-id-32560Thank you! I suppose the question is answered and I should monitor track ticket from now on.Sat, 13 Feb 2016 15:09:27 -0600http://ask.sagemath.org/question/32513/initsage-doesnt-work-for-the-notebook-server/?comment=32560#post-id-32560