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

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

Related

Issue with Pylance and matplotlib

I have looked at these problems online but I don't seem to be able to find a good answer.
System details:
Mac OS BigSur 11.6 on a M1 MacBook Pro
Installed miniforge as discussed here
Installed VSCode for Mac
I have these two following (unrelated?) problems when using jupyter notebook:
PyLance does not resolve imports like numpy etc. I see that os or sys are recognized and resolved but pretty much nothing else is. The kernel used by the jupyter notebook is the correct one. Indeed I am able to run the code with no issues but I get all these unrecognized imports.
I am not able to run the jupyter notebook with %matplotlib notebook. I can run with %matplotlib inline, but then I am not able to see the widgets to zoom in etc. To be more precise, if I try to plot in a cell then after it I see the following:
either nothing or
the following <IPython.core.display.HTML object>
This is achieved by clicking on the symbol </> and changing the rendered from html to text.
I am wondering if there is some issue with my installation of python and jupyter on the M1 or it is a VSCode issue. Any suggestion on where to look into the problem(s)?

Jupyter - ending multiline magic command in console

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.

convert ipython notebook to python without ipython

Is there an easy way to convert an ipython notebook to plain python without using ipython itself (i.e. not using ipython nbconvert --to=python ...)?
Background: I want to test if there is a syntax error in various ipython notebooks using travis-ci. However, installing ipython from source takes too long and the ubuntu packages are outdated.
I wrote a simple script that does the conversion. It's probably not fool-proof but works for me. I'd still be happy to hear about a better solution.
Link to script: https://gist.github.com/hannorein/8423ad75547f37bba228

pylab backend from cmd prompt?

I've run into an issue...
First, I've been trying (with little success yet) of 'packaging' a Canopy python file into an .exe. I'm trying to make a 'simple' way to run our program(s) for our client.
With those issues, I thought I'd make a .cmd file with 'python myprog.py' in it. Well, it fires up my code without having the Canopy environment there to confuse my end-users, BUT, it appears that the PyLab backend isn't Qt4, as the screen appears quite a bit different, and the actual program doesn't quite run the same :(
Is there some way to tell Canopy that when I start a program using 'python xxx.py' that it should be using the Qt4 package? I've looked at the Preferences for Canopy, and both the Notebook tab and the Python tab have the PyLab backend set to Interactive (Qt4)? If I can find that and get my panels to look the same as in the Canopy environment, I'll see if the rest of the program straightens out too.
Steve, if you wish you can hard-code this into your program, but as a quick solution, precede your python call with:
set ETS_TOOLKIT=qt4

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