XD blog

blog page

ipython


2015-08-14 IPython becomes Jupyter

It was announced on their blog but the module IPython was split in many modules. Here is the list I needed to install while upgrading to Jupyter 4.0.

ipykernel
ipython
ipython_genutils
ipywidgets
jupyter
jupyter_client
jupyter_core
jupyter-console
nbformat
nbconvert
notebook
path.py
pickleshare
qtconsole
simplegeneric
traitlets

With Anaconda, you get all these updates by typing: conda install jupyter.

2015-02-05 Run a IPython notebook offline

I intensively use notebooks for my teachings and I recently noticed that some of them fail because of I updated a module or I did some changes to my python installation. So I thought I looked for a way to run my notebooks in batch mode. I found runipy which runs a notebook and catches exception it raises. After a couple of tries, I decided to modify the code to get more infos when it fails. It ended up with a function run_notebook:

from pyquickhelper.ipythonhelper.notebook_helper import run_notebook
output = run_notebook(notebook_filename, 
             working_dir=folder, 
             outfilename=outfile)

I think it is going to save some time from one year to the next one.

2014-12-15 Convert a notebook into HTML from a notebook and others tricks

The notebook Convert a notebook into a document explains how to convert a notebook into a HTML page from the notebook itself. It also gives two others tricks: how to get the notebook filename and how to create a link to a local file. The second trick is quite interesting for those who use a remote notebook. It is easy to write code to download data from the notebook. The data will be placed on the remote machine. Once you've played with it, you usually get results or others data. But if the only access to this machine is through a notebook, you can add a link to this local data instead of upload this data somewhere on the cloud or a website. See also FileLink.

Some others unrelated tricks. I tried in the following notebook the new version of matplotlib which allows zoomable graphs in a notebook: Graphe zoomable avec Matplotlib (French). I still prefer mpl3d.

2014-11-12 Notebook sur iPad

Après avoir installé un serveur de notebook sur une machine distante (voir Remote Notebook with Azure), j'ai voulu essayer depuis un iPad. Cela ne fonctionne pas à cause d'une erreur de WebSocket. Ca ne marche pas mieux avec Chrome (la solution proposée dans cette page ne marche pas). Il exite néanmoins l'application Computable pour iPad. Elle est gratuite pour essayer et payant pour créer ses propres notebooks. Elle utilise Python 2.7.

2014-11-11 SQLite in a Notebook with Magic Commands

Whenever I need to use SQLite, most of the time, I don't use Python because I don't do it often enough to remember the syntax. I usually use SQLiteSpy. However, converting any result to a dataframe is impossible unless I copy paste the results somewhere. So I implemented some magic commands in pyensae you can see in the notebook SQL Magic Commands with SQLite in a Notebook.

2014-11-09 Remote Notebook with Azure

For my teachings, I installed a notebook server on a virtual machine on Azure. All the students will be able to connect the same login (the multi-user configuration is part of the roadmap). The students will not have to install the notebooks by themselves. They will be able to see what other students users do. Here are the steps I followed.

Step 1: create the virtual machine with Azure

I won't detail that, it is pretty straight forward. Just follow the tutorial Create a Virtual Machine Running Windows. I chose a Windows Server. The number of cores must depend on the number of users. I assume all students are not going to access the notebook at the same time except during the lectures. I chose eight cores. I might modify this post in case it is not enough.

Step 2: install Python (latest version - 3.4 today)


more...

2014-10-23 Fix table of contents in a Notebook

When I have a long notebook, I find it difficult to navigate through it. Maybe I should not do that. However, some outputs are quite long sometimes and the page gets longer. I usually put a table of contents at the beginning but it means I need to go back to the top of the page anytime I want to go to a specific section. That's why I tried a table of contents in a section div with an absolute position (the notebook is here). It works nice even if the mix between markdown and HTML gives weird results sometimes. The only drawback is the conversion of the notebook into HTML or rst. The table of contents shows up at the top of the page at the expected place but disappears after the page was scrolled down.

2014-09-27 Comment récupérer un notebook ?

Il existe de nombreux notebooks disponibles sur internet comme A gallery of interesting IPython Notebooks. Pour récupérer un notebook comme ceux de mon cours, le plus simple est de les télécharger pour les enregistrer dans le répertoire courant de Python une fois que les notebook sont lancés. Pour obtenir cette information, le plus simple est de créer un nouveau notebook et d'exécuter le code suivant :


more...

2014-09-20 Magic command %%CS for IPython Notebook

The notebooks IPython offer a couple of magic command to run others language such %%R, %%octave or %%julia. I found one option for F# but nothing on something like %%CS. However, magic commands are quite easy to handle. It is not that difficult to add one which allows me to do that:

%%CS mypower System.dll
public static double mypower(double x, double y)
{
    if (y == 0) return 1.0 ;
    return System.Math.Pow(x,y) ;
}

To be able to call it that way:

mypower(3.0,3.0)

more...

2014-09-14 Ajouter des commandes magiques en IPython

IPython a beaucoup de magic commands. Et on peut même ajouter les siennes. Comme je suis sûr d'oublier la syntaxe, je l'ai mise ici : custom_magics.py.

2014-09-07 Four issues I had when using IPython, R and rmagic

I wanted to use R through IPython notebook to mix Python and R. I did it on Windows and I guess it requires to be more careful. I went through four issues.


more...

2014-08-05 Custom completion for IPython

Autocompletion is a nice feature quite useful when typing very long names. It is implemented by modules such as IPython, bpython or DreamPie. I'm quite a big fan of a the first one, the notebooks to be precise. However, it did not seem quite easy to add my custom autocompletion. I tried some search queries but I was only able to find Integrating your objects with IPython or IPEP 11: Tab Completion System Refactor.


more...

2014-08-03 Customize IPython notebooks

If you want to customize your notebooks and finds a style which suits you better, you can look into these links and try one of these options:

2014-02-26 Installer Python pour faire des statistiques

L'environnement que je suggère est celui que j'utilise pour préparer mes cours. Il permet d'utiliser les outils que je propose et d'obtenir un espace de travail équivalent à celui que propose R. Plusieurs options sont possibles :

Je poursuivrai par l'installation de pyensae, et je terminerai par la configuration de l'éditeur SCite qui est, de mon point de vue, le plus simple éditeur qui soit mais il fait bien ce pour quoi il est fait.

2014/10/25

Si je devais choisir une distribution, ce serait Anaconda. C'est la plus à jour et la plus complète. Une fois installée, elle devient la distribution par défaut sous Linux. Cela évite les confusions entre les différentes versions de Python (Python 2.7 est installée par défaut). Sous Windows, elle est plus complète que WinPython. Elle inclut notamment le package paramiko dont je me sers pour ouvrir une connexion SSH avec un serveur Linux et utiliser PIG.

Préliminaire

Il existe deux numéros de versions important à retenir :

Une fois choisis ces deux numéros de versions pour l'installation de Python, si ces versions sont précisées pour un module, alors il faudra choisir exactement ces deux mêmes versions.

WinPython


more...

2014-02-24 Travailler avec IPython notebook

Si l'environnement que R proposait était il y a encore quelques temps le meilleur compromis pour quiconque voulait faire des statistiques ou du machine learning, de mon point de vue, IPython a changé la donne. On peut toujours travailler avec un éditeur texte classique, ou avec une ligne de commande similaire à celle de R ou encore utiliser les notebook. Un notebook, c'est un peu comme une page blanche ou on mélange à la fois du texte, du code, des graphiques, des équations et même du javascript. C'est très pratique lorsqu'on cherche sa partition. Entendez par là que vous avez un problème à résoudre mais pas encore la solution. Il faut donc expérimenter. Cette page blanche vous permet facilement de garder une trace de tous vos essais et de les annoter puis de rédiger le document final. Pour vous en convaincre, il suffit d'aller voir la gallerie suivante (également A gallery of interesting IPython Notebooks), et on peut faire des choses assez marrantes (XKCDify) voire même utiliser R depuis IPython (Using R Within the IPython Notebook).

Pour essayer, l'option la plus rapide et de télécharger la distribution WinPython qui contient tous les packages intéressants pour un statisticien (ou data scientist). Il ne vous faudra pas très longtemps pour lancer le notebook et de là, découvrir par vous-même comment cela fonctionne. Il n'y a pas trente six mille boutons et tout est plutôt intuitif.


more...
-->

Xavier Dupré