Ask Your Question
1

lsmagic doesn't work

asked 2020-09-25 02:50:55 +0100

cybervigilante gravatar image

When I try to list magic functions with %lsmagic, all I get is <ipython.core.magics.basic.magicsdisplay object="" at="" 0x6fec56dd780=""> Can I access this object somehow?

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2020-09-25 12:51:37 +0100

Emmanuel Charpentier gravatar image

%lsmagic seems to need some initialization not provided when starting sage (which, BTW, runs into an (invisible) IPython session). In a terminal :

charpent@zen-book-flip:~$ sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 9.2.beta13, Release Date: 2020-09-21              │
│ Using Python 3.8.5. Type "help()" for help.                        │
└────────────────────────────────────────────────────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Warning: this is a prerelease version, and it may be unstable.     ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sage: %lsmagic                                                                  
<IPython.core.magics.basic.MagicsDisplay object at 0x7f823866f0d0>

Failure as reported. But :

sage: %display unicode_art                                                      
sage: %lsmagic                                                                  
Available line magics:
%alias  %alias_magic  %attach  %autoawait  %autocall  %autoindent  %automagic  %axiom  %bookmark  %cat  %cd  %clear  %colors  %conda  %config  %cp  %cpaste  %crun  %debug  %dhist  %dirs  %display  %doctest_mode  %ed  %edit  %env  %fricas  %gap  %gap3  %giac  %gp  %gui  %hist  %history  %iload  %kash  %killbgscripts  %ldir  %less  %lf  %lie  %lisp  %lk  %ll  %load  %load_ext  %loadpy  %logoff  %logon  %logstart  %logstate  %logstop  %ls  %lsmagic  %lx  %macaulay2  %macro  %magic  %magma  %man  %maple  %mathematica  %matlab  %matplotlib  %maxima  %mkdir  %more  %mupad  %mv  %mwrank  %notebook  %octave  %page  %paste  %pastebin  %pdb  %pdef  %pdoc  %pfile  %pinfo  %pinfo2  %pip  %polymake  %popd  %pprint  %precision  %prun  %psearch  %psource  %pushd  %pwd  %pycat  %pylab  %quickref  %r  %recall  %rehashx  %reload_ext  %rep  %rerun  %reset  %reset_selective  %rm  %rmdir  %run  %runfile  %sage0  %save  %sc  %scilab  %set_env  %singular  %store  %sx  %system  %tb  %time  %timeit  %unalias  %unload_ext  %who  %who_ls  %whos  %xdel  %xmode

Available cell magics:
%%!  %%HTML  %%SVG  %%axiom  %%bash  %%capture  %%cython  %%debug  %%file  %%fortran  %%fricas  %%gap  %%gap3  %%giac  %%gp  %%html  %%javascript  %%js  %%kash  %%latex  %%lie  %%lisp  %%macaulay2  %%magma  %%maple  %%markdown  %%mathematica  %%matlab  %%maxima  %%mupad  %%mwrank  %%octave  %%perl  %%polymake  %%prun  %%pypy  %%python  %%python2  %%python3  %%r  %%ruby  %%sage0  %%scilab  %%script  %%sh  %%singular  %%svg  %%sx  %%system  %%time  %%timeit  %%writefile

Automagic is ON, % prefix IS NOT needed for line magics.

And now:

sage: sqrt(x)                                                                   
√x

Ditto when you start with %display ascii_art, but not when you start with %display simple.

Even more interesting, switching back to %display default DISABLES %lsmagic. Nice bug (or buglet...).

This is now Trac#30661.

edit flag offensive delete link more
1

answered 2020-09-25 07:43:10 +0100

dyne2meter gravatar image

Yes, I get that response when I issue the command at the standard Sage command line interface.

However if I start Sage with "sage --ipython", I get the ipython interface, and from there, %lsmagic works fine.

edit flag offensive delete link more

Comments

Note that sage -ipython starts a Python session in an IPython console : to get the Sage REPL, you need to %load_ext sage :

charpent@zen-book-flip:~$ sage --ipython
Python 3.8.5 (default, Aug  2 2020, 15:09:07) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.13.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: 2^3                                                                     
Out[1]: 1         # In Python "^" is XOR

In [2]: %load_ext sage                                                          

In [3]: 2^3                                                                     
Out[3]: 8        # In Sage, "^" is exponentiation.
Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2020-09-25 12:58:41 +0100 )edit

Thanks for this. I am still low on the learning curve with how all the front-end pieces work together. I have run across some info about how to run Sage within a Python session started the same way, but didn't connect it to the same idea in ipython. Truth be told, I don't use ipython (or sage --python) much, so far, and have been concentrating on the Jupyter notebook interface. Getting a handle on the line magics is going to help me at some point in the near future.

So far, I am using the default python and ipython that I get with the built 9.1 system that I download. Another item on my list is upgrading these components using the package manager or whatever it is called, but I will probably just wait for 9.2 and see what I get.

dyne2meter gravatar imagedyne2meter ( 2020-09-26 09:05:36 +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

1 follower

Stats

Asked: 2020-09-25 02:50:55 +0100

Seen: 1,729 times

Last updated: Sep 25 '20

Related questions