Ask Your Question

python file in package not working, not recognizing "integrate" method, why?

asked 2012-09-27 00:07:21 +0200

SLOtoSF gravatar image

updated 2012-09-27 01:01:28 +0200

Hi! I have spent more than 40 hours figuring out how to install linux, then sage (from source), and even got a github account going for a new project.

I have a python file which only has the text:

def testThis(): var('x') return integrate(x,x)

But I am getting an error about the var command. If i remove it then it doesn't even recognize the integrate command.

What do I need to do in order for sage to recognize these commands? They work in sage, but why won't they work in python?

Many Thanks! I can't wait to actually start programming!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2012-09-27 00:24:45 +0200

kcrisman gravatar image

No, because Sage is (more or less) a superset of Python. If you make your file my_file.sage instead of, that would clear up some of the trouble, if you run it from within Sage.

You aren't quite clear how you're running this. The best way to do it is to open Sage, and then use the load or attach commands to attach this specific file (use load? or attach? to get more info from within Sage). I'm assuming you're using the command line.

If you're doing it from Sage's Python or some other Python that has access to Sage (somehow), then you may need to put a blanket import statement like from sage.all import * at the top of your file - there are other questions on this help forum which can help you. Good luck and please follow up with more information about your situation if you need to!

edit flag offensive delete link more


Thanks. Here's what I'm doing: I followed the directions here: In this example they only use .py files, so I'm assuming that there will be an issue if I use .sage files... ? Also when you import it seems you only use the name of the file without the extension...

SLOtoSF gravatar imageSLOtoSF ( 2012-09-27 00:35:24 +0200 )edit

Right, this is for something you are ''including'' in Sage, or intending to be included in Sage. For your own separate project (which it would be for now) it's fine to make something a Sage file. The part without the extension is part of what is called "making a module", which you can easily search for - good luck!

kcrisman gravatar imagekcrisman ( 2012-09-27 09:15:35 +0200 )edit

Perfect it worked! Adding from sage.all import * saved the day. Thanks.

SLOtoSF gravatar imageSLOtoSF ( 2012-09-27 14:26:11 +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


Asked: 2012-09-27 00:07:21 +0200

Seen: 312 times

Last updated: Sep 27 '12