ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 27 Sep 2012 07:26:11 -0500python file in package not working, not recognizing "integrate" method, why?https://ask.sagemath.org/question/9353/python-file-in-package-not-working-not-recognizing-integrate-method-why/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!Wed, 26 Sep 2012 17:07:21 -0500https://ask.sagemath.org/question/9353/python-file-in-package-not-working-not-recognizing-integrate-method-why/Answer by kcrisman for <p>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. </p>
<p>I have a python file which only has the text:</p>
<p><code>
def testThis():
var('x')
return integrate(x,x)
</code></p>
<p>But I am getting an error about the var command. If i remove it then it doesn't even recognize the integrate command.</p>
<p>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?</p>
<p>Many Thanks! I can't wait to actually start programming!</p>
https://ask.sagemath.org/question/9353/python-file-in-package-not-working-not-recognizing-integrate-method-why/?answer=14068#post-id-14068No, because Sage is (more or less) a superset of Python. If you make your file `my_file.sage` instead of `my_file.py`, 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!Wed, 26 Sep 2012 17:24:45 -0500https://ask.sagemath.org/question/9353/python-file-in-package-not-working-not-recognizing-integrate-method-why/?answer=14068#post-id-14068Comment by SLOtoSF for <p>No, because Sage is (more or less) a superset of Python. If you make your file <code>my_file.sage</code> instead of <code>my_file.py</code>, that would clear up some of the trouble, if you run it from within Sage.</p>
<p>You aren't quite clear how you're <em>running</em> this. The best way to do it is to open Sage, and then use the <code>load</code> or <code>attach</code> commands to attach this specific file (use <code>load?</code> or <code>attach?</code> to get more info from within Sage). I'm assuming you're using the command line.</p>
<p>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 <code>from sage.all import *</code> 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!</p>
https://ask.sagemath.org/question/9353/python-file-in-package-not-working-not-recognizing-integrate-method-why/?comment=19005#post-id-19005Thanks. Here's what I'm doing: I followed the directions here: http://www.sagemath.org/doc/developer/coding_in_python.html#creating-a-new-directory
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...Wed, 26 Sep 2012 17:35:24 -0500https://ask.sagemath.org/question/9353/python-file-in-package-not-working-not-recognizing-integrate-method-why/?comment=19005#post-id-19005Comment by kcrisman for <p>No, because Sage is (more or less) a superset of Python. If you make your file <code>my_file.sage</code> instead of <code>my_file.py</code>, that would clear up some of the trouble, if you run it from within Sage.</p>
<p>You aren't quite clear how you're <em>running</em> this. The best way to do it is to open Sage, and then use the <code>load</code> or <code>attach</code> commands to attach this specific file (use <code>load?</code> or <code>attach?</code> to get more info from within Sage). I'm assuming you're using the command line.</p>
<p>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 <code>from sage.all import *</code> 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!</p>
https://ask.sagemath.org/question/9353/python-file-in-package-not-working-not-recognizing-integrate-method-why/?comment=19002#post-id-19002Right, 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!Thu, 27 Sep 2012 02:15:35 -0500https://ask.sagemath.org/question/9353/python-file-in-package-not-working-not-recognizing-integrate-method-why/?comment=19002#post-id-19002Comment by SLOtoSF for <p>No, because Sage is (more or less) a superset of Python. If you make your file <code>my_file.sage</code> instead of <code>my_file.py</code>, that would clear up some of the trouble, if you run it from within Sage.</p>
<p>You aren't quite clear how you're <em>running</em> this. The best way to do it is to open Sage, and then use the <code>load</code> or <code>attach</code> commands to attach this specific file (use <code>load?</code> or <code>attach?</code> to get more info from within Sage). I'm assuming you're using the command line.</p>
<p>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 <code>from sage.all import *</code> 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!</p>
https://ask.sagemath.org/question/9353/python-file-in-package-not-working-not-recognizing-integrate-method-why/?comment=18998#post-id-18998Perfect it worked! Adding from sage.all import * saved the day. Thanks.Thu, 27 Sep 2012 07:26:11 -0500https://ask.sagemath.org/question/9353/python-file-in-package-not-working-not-recognizing-integrate-method-why/?comment=18998#post-id-18998