On Sun, Mar 15, 2009 at 4:00 PM, bjrnfrdnnd <[email protected]> wrote: > > Hi, > I have installed sage 3.4 from source. > I want to use sage in my python scripts, particularly the linear > algebra part. > I therefore want to write little python scripts with something like > > m=matrix([[1,2],[3,4]]) > e=m.eigenvalues() > > My only problem is: what should I import in order to make this kind of > thing work? > > I figured out that you seemingly can import > import sage.all > > This seems to reproduce the sage command-line functionality, i.e. I > can do > > import sage.all > m=sage.all.matrix([[1,2],[3,4]]) > e=m.eigenvalues() > > However, I am not sure about that, and I did not find out where in > what manual this is explained. > And, I am importing a huge piece of software with this command.
To use any part of Sage you absolutely *MUST* import sage.all. Sage is highly interdependent, and one can't just import little bits and pieces. > Therefore, I want to try something else. Looking up "eigenvalues" in > the reference manual, I find that it resides in > sage.matrix.matrix2.Matrix This will segfault and fail horribly, so you shouldn't do it. Doing "import sage.all" causes Sage to properly and in the right order initialize itself - importing random things out doesn't. -- William > > So, what I would like to do, is > import sage.matrix.matrix2 > and then use Matrix. > > However, this does not work: when trying to do this import, > python reports an error. > > Here is the way to reproduce this error: > > cd $SAGE_ROOT/loca/bin > source sage-env > ./python >>>>import sage.matrix.matrix2 > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > File "matrix2.pyx", line 1, in sage.matrix.matrix2 (sage/matrix/ > matrix2.c:32616) > File "matrix1.pyx", line 1, in sage.matrix.matrix1 (sage/matrix/ > matrix1.c:9974) > File "matrix0.pyx", line 32, in sage.matrix.matrix0 (sage/matrix/ > matrix0.c:19609) > File "/home/bn/sage-3.4/local/lib/python2.5/site-packages/sage/ > modules/free_module.py", line 163, in <module> > import free_module_element > File "free_module_element.pyx", line 111, in > sage.modules.free_module_element (sage/modules/free_module_element.c: > 19756) > File "/home/bn/sage-3.4/local/lib/python2.5/site-packages/sage/rings/ > arith.py", line 18, in <module> > import sage.rings.rational_field > File "/home/bn/sage-3.4/local/lib/python2.5/site-packages/sage/rings/ > rational_field.py", line 52, in <module> > import rational > File "rational.pyx", line 63, in sage.rings.rational (sage/rings/ > rational.c:17816) > File "real_mpfr.pyx", line 143, in sage.rings.real_mpfr (sage/rings/ > real_mpfr.c:25879) > AttributeError: 'module' object has no attribute 'QQ' > > > > What is going wrong? And how should I, in general, use sage in a > python script? Remember that there was no > way to find out from the eigenvalues entry in the reference manual > that you could actually import sage.all and use sage.all.matrix... > So I do actually not know how to figure out that kind of problems in > the future. If the > import sage.matrix.matrix2 > would work, > I could use sage quite straightforwardly in my scripts, as I would > then be able to use the info in the reference manual. > > Thank you for your help! > > > > -- William Stein Associate Professor of Mathematics University of Washington http://wstein.org --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---
