Jupyter - ending multiline magic command in console - ipython

In a Jupyter notebook, a "cell magic" command (prefixed with two percent signs) ends at the end of the cell and is automatically invoked:
But if I try the same thing in the Jupyter console, the command never ends, after any number of blank lines:
That only happens if I invoke IPython as jupyter console, though. If I invoke IPython directly as ipython, the cell magic command completes after one blank line:
For each example, the versions of Python and IPython are identical: Python 3.5.2 and IPython 6.1.0 on one machine (installed with pip), Python 3.4.5 and IPython 5.1.0 on another (installed with Conda).
Is this a bug? Or is there Jupyter default configuration somewhere for IPython that differs from IPython's own default configuration?

Yes, it is a bug, the cell magics are suppose to ends after 2 new lines.
The Jupyter console is way under maintained – we are not aware of many people using it, and it has plenty of issues.
Technically I believe the jupyter console does not use (or respect) the "is_complete" message from the protocol that should tell it wether the snippet of code should be executed or if a newline should be inserted.
You can try to open a bug report, but the fix will probably not be implemented quickly unless someone does a PR.

Related

How can I programmatically check that I am running code in a notebook in julia?

I would need to programmatically check that I am running code in a jupyter notebook from Julia. One way would be using
isdefined(Main, :IJulia)
However this does not work for notebooks within vscode since they are run from outside IJulia is there a check that would work in this case as well?
What about #__FILE__ this yields REPL[_] in Julia REPL, In[_] in Jupyter and "/path/to/file.jl#==#hashocde" in Pluto so the test could be:
match(r"^In\[[0-9]*\]$", #__FILE__) != nothing
and in VSCode:
so you can check if the file ends with ".ipynb" if you want to find VSCode. Moreover: isdefined(Main, :VSCodeServer) yields true if you run from VSCode.

IPython Notebook interprets empty lines from save_script output

I use the save_script = True option in the IPython Notebook config file to save a script file of my notebooks. One of these script (.py) files I add to my /Python27/ArcGISXX/Lib/ directory and then I have recently ran into a problem where
I've found that with the most recent version of IPython, that when I use save_script = True, IPython interprets the .py file with blank lines added between each line. So I try to import this .py file like a package and it has syntax errors because it interprets blank lines between every line. Is this happening to anyone else? How can I address it?
I am running Windows 7 and have IPython installed with the "Background Geoprocessing (64-bit)" installation of Python 2.7 for ArcMap.
Reposting as an answer:
This was a bug in IPython 2.3.0; we released the fix as 2.3.1.
For those who want the details, here's the bug report and the pull request that fixed it.

Stop ipython pop-up docs

In the ipython qtconsole it automatically displays the documentation for a function when I type the opening parenthesis. For example, when I'm typing
plt.show()
the documentation for pyplot.show is displayed when I've typed
plt.show(
This documentation is displayed in a pop-up window that, much more often than not, blocks my view what I'm typing. Is there a configuration to stop the ipython qtconsole from doing this?
The feature to which you refer is calltips or more precisely IPythonWidget.enable_calltips and is documented at https://ipython.org/ipython-doc/dev/config/options/qtconsole.html. The only effective way I have found to disable it is by adding --IPythonWidget.enable_calltips=False as an argument to qtconsole that in turn an argument of ipython. A command line for all of this is:
ipython qtconsole --IPythonWidget.enable_calltips=False
I have verified this with IPython QTConsole 3.2.0 and believe it generally works for versions below 4, which I have not been able to install yet without breaking QTConsole. (I believe what some refer to as IPython 4 is also known as Jupyter 4. See below for information on Jupyter and disabling calltips in it.)
On Linux and Windows system, generating this command line can be automated using a bash alias. On Windows it can be automated by using it as the Target of an icon configured in its properties.
It is supposed to be possible to disable calltips by setting c.IPythonWidget.enable_calltips = False in the right configuraton file in which c = get_config() is set on the first line. I tried doing this on a Windows 7 system in ipython_qtconsole_config.py and ipython_config.py in ~.ipython\profile_default\ and several other locations, but could not get it to work.
Project Jupyter is the successor to the IPython project and began in 2014. Its website is http://jupyter.org and information about its Qt console is at http://jupyter.org/qtconsole/stable/index.html. In response to a question about disabling IPython calltips, which I submitted to https://github.com/ipython/ipython/issues, I received the following on how to disable calltips for Jupyter:
On the command line
jupyter qtconsole --JupyterWidget.enable_calltips=False
or add
c.JupyterWidget.enable_calltips = False
to
~/.jupyter/juptyer_qtconsole_config.py

How to use ipython ZMQ-based console by default

I often use ipython with vim (vim-ipython plugin). It connects to ipython via ZMQ, so I need to run ipython console. I don't see any purpose to not use ipython console even if I don't use ZMQ features, so I want ipython to start ZMQ-based console without typing console. I know, that this problem could be partly solved with bash aliases, but I think that I would have problems with launching qtconsole or notebook.
We don't provide any way to make ipython console the default, and we're probably not about to, as it gets much less field testing than the regular terminal IPython. I'd recommend you just alias another convenient name to it.

Display of music21, musicXML PNG objects using iPython Notebook/Enthought Canopy

I am experimenting with the music21 library, in preparation for a Machine Learning project that involves genre classification and categorization. I and following some tutorials available here. I am using MuseScore as my MusicXML program, and I am trying to run the whole thing from iPython.
Although I can run the some of the turtorials from the terminal, some elements don't seem to run well from inside iPython. For example:
In [3]: sBach.show()
Out[3]: <music21.ipython21.objects.IPythonPNGObject at 0x10da0aa10>
The line above shows that the PNG object is created, but not displayed. The expected output for 3 above is the following:
Experimenting with the following iPython command, I get a placeholder for an image, but not image.
In [6]: %load_ext music21.ipython21.ipExtension
In [7]: sBach.show()
I can't find any problem with my MusicXMLPath. This tutorial refers to the use of musc21 with Anaconda, but all my developments is done with Enthought, so I prefer not to run another virtual environment to use music21 with iPython.
Is there any way to run music21 in an Enthought/iPython notebook?
I have been grappling with this issue myself. ... Have you set your musicxmlPath in music21? If you have not, it's done via environment.set(key, value). You can query for available keys with environment.keys(). I hope this isn't too simple an answer, but it cleared up the problem for me.
This should be in the iPython music21 documentation somewhere, my apologies: iPython in music21 requires Lilypond to be installed for images to be generated within the notebook itself. There hasn't been (and won't be until MuseScore 2.0 is released) a way using MusicXML to generate PNG images of scores directly.
Edit: 2015 July; music21 2.0 w/ MuseScore 2 will generate the PNG images with MuseScore if it is installed and fallback to Lilypond if it is not installed.
If not yet tried, some steps to isolate the cause of the problem:
1) Update to the latest Canopy (Edit: currently 1.4.1) (might help this, will help generally, won't hurt).
2) Change the Pylab backend in Canopy's IPython shell to "Inline (SVG)", via Preferences / Python. (The default Qt backend in that shell conflicts with music21's use of the tkinter library.)
3) Test your script in that shell rather than in the notebook.
4) Ensure that Canopy User Python is your default Python in a Terminal window, as described here.
5) Test your scripts inside of plain ipython terminal (from Terminal, type ipython).
6) Test in ipython terminal in pylab mode (ipython qtconsole --pylab=inline).
7) Test your scripts inside of ipython notebook running in a regular browser (from Terminal, type ipython notebook, and/or ipython notebook --pylab=inline).
Had similar issues before. It's the same problem when people try to use plot function in ipython/jupyter notebook. You need to call
%matplotlib inline
For me the issue was solved by uninstalling the snap version of musescore and installing it from ppa:mscore-ubuntu/mscore3-stable via https://launchpad.net/~mscore-ubuntu/+archive/ubuntu/mscore3-stable