ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 25 Apr 2012 19:38:56 +0200How to import a module at startup?https://ask.sagemath.org/question/8929/how-to-import-a-module-at-startup/Hello, I'm new to sage and have been trying to import numpy when starting up sage for a few hours now. I've searched everywhere and so far i've tried the following options:
Editing the import_all variable in .sage/ipython/ipythonrc
import_all numpy
I've also tried adding some execute instructions in the ipythonrc
execute print "test"
execute from numpy import *
The thing is, the first line works and writes "test" to the console, but the import statement doesn't seem to work.
Finally, I've edited the main function in .sage/ipython/ipy_user_conf like this:
def main():
from numpy import *
o = ip.options
ip.ex('from numpy import *')
main()
But this doesn't seem to work either. When I try to create a new column matrix like this:
a=matrix("[1; 2; 3; 4]")
I get an error which is solved by manually importing the numpy libs.
Is there any other way to automatically load modules at startup? Am I missing something?
Thanks in advance for any help.
Wed, 25 Apr 2012 19:28:21 +0200https://ask.sagemath.org/question/8929/how-to-import-a-module-at-startup/Answer by Tom Dorris for <p>Hello, I'm new to sage and have been trying to import numpy when starting up sage for a few hours now. I've searched everywhere and so far i've tried the following options:</p>
<p>Editing the import_all variable in .sage/ipython/ipythonrc</p>
<pre><code>import_all numpy
</code></pre>
<p>I've also tried adding some execute instructions in the ipythonrc</p>
<pre><code>execute print "test"
execute from numpy import *
</code></pre>
<p>The thing is, the first line works and writes "test" to the console, but the import statement doesn't seem to work.</p>
<p>Finally, I've edited the main function in .sage/ipython/ipy_user_conf like this:</p>
<pre><code>def main():
from numpy import *
o = ip.options
ip.ex('from numpy import *')
main()
</code></pre>
<p>But this doesn't seem to work either. When I try to create a new column matrix like this:</p>
<pre><code>a=matrix("[1; 2; 3; 4]")
</code></pre>
<p>I get an error which is solved by manually importing the numpy libs.
Is there any other way to automatically load modules at startup? Am I missing something? </p>
<p>Thanks in advance for any help.</p>
https://ask.sagemath.org/question/8929/how-to-import-a-module-at-startup/?answer=13500#post-id-13500I read somewhere that the .sage/init.sage file gets executed at startup, but I haven't tried it myself.Wed, 25 Apr 2012 19:31:42 +0200https://ask.sagemath.org/question/8929/how-to-import-a-module-at-startup/?answer=13500#post-id-13500Comment by Levelpart for <p>I read somewhere that the .sage/init.sage file gets executed at startup, but I haven't tried it myself.</p>
https://ask.sagemath.org/question/8929/how-to-import-a-module-at-startup/?comment=19863#post-id-19863Wow it worked! All this time searching and it was this easy, thanks a lot Tom.
I still don't understand why some "execute" instructions in the iphythonrc wouldn't work though.Wed, 25 Apr 2012 19:38:56 +0200https://ask.sagemath.org/question/8929/how-to-import-a-module-at-startup/?comment=19863#post-id-19863