Ask Your Question
1

IP-Notebooks and extensions, Sage versus Sage Cloud

asked 2014-07-05 17:12:23 +0200

Peter Luschny gravatar image

updated 2014-11-26 11:43:37 +0200

In Sage Math Cloud I can open an IP:Notebook, execute

%load_ext sage

and Sage runs whithin the IP:Notebook.

Trying to do the same with my local IPython fails. I get an ImportError:

../IPython/core/extensions.py in load_extension(self, module_str)
     96             if module_str not in sys.modules:
     97                 with prepended_to_syspath(self.ipython_extension_dir):
---> 98                     __import__(module_str)
     99             mod = sys.modules[module_str]
    100             if self._call_load_ipython_extension(mod):

ImportError: No module named 'sage'

Where can I get this module 'sage'? Or is it private to SMC?

-- EDIT -- [26-11-2014]

According to slelievre below:

"In Sage 6.4.beta6 or later, $ sage --notebook=ipython should also work."

In fact I get:

sage --notebook=ipython

Sage Version 6.4, Release Date: 2014-11-14                         │

  File "/sage-6.4/src/bin/sage-notebook", line 180, in <module>
    launcher(unknown)
  File "/sage-6.4/src/bin/sage-notebook", line 69, in __init__
    from sage.repl.notebook_ipython import SageNotebookApp
  File "/sage-6.4/local/lib/python2.7/site-packages/sage/repl/notebook_ipython.py", line 14, in <module>
    from IPython.html.notebookapp import NotebookApp
  File "/sage-6.4/local/lib/python2.7/site-packages/IPython/html/notebookapp.py", line 62, in <module>
    from tornado import httpserver
  File "/sage-6.4/local/lib/python2.7/site-packages/tornado-3.1.1-py2.7.egg/tornado/httpserver.py", line 30, in <module>
    import ssl
  File "/sage-6.4/local/lib/python/ssl.py", line 60, in <module>
    import _ssl             # if we can't import it, let the error propagate

ImportError: No module named _ssl
edit retag flag offensive close merge delete

Comments

I've probably just put me inadvertently on the bleeding edge of the technology. It seems that this is a question of version and hopefully with Sage 6.3 the problems will be solved.

Peter Luschny gravatar imagePeter Luschny ( 2014-07-13 19:58:47 +0200 )edit

About your 2014-11-26 edit: I tried in Sage 6.5.beta1 and it works, I currently don't have 6.4. The error message suggests that your python is missing the _ssl module. I suggest opening a new question (with a link to this one) telling more about your current problem, including information such as operating system, whether you are using a binary distribution or you built Sage from source, etc.

slelievre gravatar imageslelievre ( 2014-11-26 21:08:52 +0200 )edit

I installed Sage 6.4 from sources on Ubuntu 14.04. By chance I found this message indicating also the reason for the failure: https://groups.google.com/d/msg/sage-...

Peter Luschny gravatar imagePeter Luschny ( 2014-11-27 17:41:38 +0200 )edit

I have now downloaded the binaries of the updated Sage 6.4.1 and things now work, finally.

Peter Luschny gravatar imagePeter Luschny ( 2014-11-27 20:03:43 +0200 )edit

1 Answer

Sort by » oldest newest most voted
4

answered 2014-07-05 17:29:27 +0200

slelievre gravatar image

updated 2014-10-23 12:33:14 +0200

Sage in IPython and IPython notebook

You can use Sage inside IPython and IPython notebook by loading the Sage extension, which will also load the Sage preparser and let you use Sage commands in IPython or IPython notebook just as you would in Sage itself.

For this, use the IPython provided with Sage (so it knows where Sage is), and type

%load_ext sage

To run the IPython provided with Sage, type in a terminal

$ sage -ipython

or, if you want the IPython notebook,

$ sage -ipython notebook

[2014-10-23: Edit: in Sage 6.4.beta6 or later,

$ sage --notebook=ipython

should also work.]

Note that with any Sage version before 6.2.beta8, instead of %load_ext sage you should type

 %load_ext sage.misc.sage_extension

Sage extension to the IPython notebook: dependencies

The dependencies are the Tornado web framework, as well as ZeroMQ and its Python bindings PyZMQ.

[2014-10-23: Edit: Starting with Sage 6.4.beta6, these are standard packages so you have nothing to do.]

If ZeroMQ and PyZMQ are not installed, you will get an import error like

ImportError: IPython.html requires pyzmq >= 2.1.11

If ZeroMQ and PyZMQ are installed, but Tornado is not installed, you will get an attribute error like

start_ipython()
File "/sage-6.2-i686-Linux/local/lib/python2.7/site-packages/numpy/lib/polynomial.py", line 11, in <module> import numpy.core.numeric as NX.
AttributeError: 'module' object has no attribute 'core'.

Recent versions of Sage ship Tornado, and upcoming versions will ship ZeroMQ and PyZMQ.

Installing Tornado

Tornado is included in Sage from 6.2.beta5 on. Why not get the latest release (Sage 6.2) or development release (Sage 6.3.beta5).

Or, for an older Sage, install Tornado as explained on the Tornado installation page. Under Linux, you can:

$ sudo apt-get install uuid-dev
$ sage -sh
$ easy_install-2.7 tornado

Installing zeromq and pyzmq

[2014-10-23: Edit: Starting with Sage 6.4.beta6, these are standard packages so you have nothing to do.]

Using older versions of Sage: in a terminal (with web access, and assuming sage points to your Sage):

$ sage -i zeromq
$ sage -i pyzmq
edit flag offensive delete link more

Comments

Hmm, how can this work? At what point do you start the IPython-notebook? "sage -ipython" gives me Ipython, however in the console mode. And calling notebook() gives me the Sage notebook, not the IP-notebook.

Peter Luschny gravatar imagePeter Luschny ( 2014-07-06 09:22:39 +0200 )edit

@Peter Luschny: I edited my answer to take your comment into account. This sould work now.

slelievre gravatar imageslelievre ( 2014-07-09 15:43:01 +0200 )edit

Thank you, slelievre! Yes, I got the same ImportError. After succeeding to install zeromq and pyzmq I tried the command "sage -ipython notebook" and this is what I got: "start_ipython() File "/sage-6.2-i686-Linux/local/lib/python2.7/site-packages/numpy/lib/polynomial.py", line 11, in <module> import numpy.core.numeric as NX. AttributeError: 'module' object has no attribute 'core'. Bottom line: still no success.

Peter Luschny gravatar imagePeter Luschny ( 2014-07-12 16:08:47 +0200 )edit

You need to install Tornado, or to update to a newer Sage. I edited my answer with details on that.

slelievre gravatar imageslelievre ( 2014-07-13 00:35:53 +0200 )edit

Thank you very much slelievre !

Peter Luschny gravatar imagePeter Luschny ( 2014-07-13 19:59:22 +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

1 follower

Stats

Asked: 2014-07-05 17:12:23 +0200

Seen: 1,144 times

Last updated: Nov 26 '14