First time here? Check out the FAQ!

Ask Your Question
1

How to import a module at startup?

asked 12 years ago

Levelpart gravatar image

updated 12 years ago

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.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 12 years ago

Tom Dorris gravatar image

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

Preview: (hide)
link

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 ( 12 years ago )

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: 12 years ago

Seen: 737 times

Last updated: Apr 25 '12