Ask Your Question
1

How to import a module at startup?

asked 2012-04-25 19:28:21 +0100

Levelpart gravatar image

updated 2012-04-25 19:36:22 +0100

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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2012-04-25 19:31:42 +0100

Tom Dorris gravatar image

I read somewhere that the .sage/init.sage file gets executed at startup, but I haven't tried it myself.

edit flag offensive delete link more

Comments

Wow 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.

Levelpart gravatar imageLevelpart ( 2012-04-25 19:38:56 +0100 )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

Stats

Asked: 2012-04-25 19:28:21 +0100

Seen: 716 times

Last updated: Apr 25 '12