XD blog

blog page

notebook


2019-03-24 Ecran blanc pour les notebooks, panique à bord

J'ai passé la nuit à coder un truc et que je lorsque je veux montrer que le code est plus rapide, j'ouvre un server de notebook pour me retrouver avec un écran blanc. Mon premier réflexe est d'essayer pas mal de navigateur pour avoir toujours le même résultat. Un écran blanc. Merde, merde, merde ! Le bug pour lequel vous n'aimez pas la programmation. Mon premier réflexe fut de réinstaller mon python en intégralité, comme sur windows, quand ça merde, on reboote.

Evidemment, après une heure d'installation, toujours la même chose. Il faut deviner le package qui ne tourne pas rond. Quelques recherches plus loin, je tombe sur cette issue while launching jupyter notebook ou celle-ci Jupyter Notebook - Blank Screen - after pip install jupyter. C'est le genre de problème qui n'apparaissait que sous Windows, allez savoir pourquoi. Bref, la solution proposée par le premier a marché. L'erreur survient quand on installe le module notebook>=5.7.6.

J'ai réinstallé mon python pour rien. Merde.

2017-01-08 La chevauchée informatique de 100 notebooks

Articule publié dans Variances 18/01/2017.

Je coordonne et j'anime environ 60 heures de cours et travaux pratiques à l'ENSAE chaque année depuis trois ans et la création de la voix datascience. Si vous allez sur mon site, vous découvrirez que la plupart de ces heures s'appuient sur des exercices écrits sous formes de notebooks et qu'une bonne partie fonctionne par paire, un énoncé, une correction, d'autres contiennent la correction des examens, d'autres répondent à des questions d'étudiants, d'autres... Le notebook est apparu il y a une dizaine d'années et est récemment devenu populaire sous le nom Jupyter. Un notebook Jupyter est un endroit où on écrit du texte, des formules, du code et où on garde la trace des graphiques et des sorties que ces petits bouts de code ont produits. C'est même un lieu où on peut insérer une carte interactive pour zoomer ou dézoomer à volonté. C'est un outil qui a rapidement trouvé son public. Rares sont les professeurs de mathématiques ou d'informatiques qui n'ont pas de notebooks d'autant plus que les étudiants peuvent les télécharger, les exécuter, que tout le monde peut aisément les convertir en PDF, html ou présentations. Essayez, allez sur un moteur de recherche, écrivez le nom d'un professeur, d'une université suivi de notebook et github... (berkely notebook github) C'est un sacré chemin parcouru depuis les polycopiés qui sentaient l'alcool. Ce sont les premières reproduction de support pédagogique qu'il m'ait été donné de découvrir. Cela vous donne d'ailleurs une idée de mon âge. J'ai découvert l'école, j'ai vécu la transition du polycopié vers la photocopie. Un pas fou ! Et depuis je mets en ligne tout ce que je produis pour mes cours, plus d'une centaine de notebooks. Tout est accessible depuis GitHub, le lieu des projets open source, tout est compilé en plusieurs sites web.


more...

2016-10-12 Convertir un notebook après filtrage

On m'a demandé récemment s'il était possible de convertir un notebook au format PDF après avoir supprimé les portions de code. La réponse est oui : Export a notebook with no code.

2015-08-24 Open the notebook with a different browser

I was looking for an easy to launch the notebook server with a different browser than the default one. I created a batch file (for Windows but easily adaptable to Linux):

set PATH=%PATH%;C:\Python34_x64;C:\Python34_x64\Scripts
set PYTHONPATH=<extra_path>;%PYTHONPATH%
set BROWSER="C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
jupyter-notebook --notebook-dir=<your_folder_for_notebooks> --port=XXXX

The notebook opens on Chrome with the following url http://localhost:XXXX.

2015-05-17 Notebook to slides

Notebooks can be converted into slides with nbconvert. It produces a slideshow with reveal.js if metadata are added to some cells. It indicates when a new slide of subslide should be started.

The trick is if you have many notebooks to convert, it is unlikely you are going to open all of them to tag each slide and subslide. So I implemented this very basic function add_tag_slide which automatically tags the cells. You can see an example of the outcome here. I also recommend to copy/paste reveal.js locally. It works better.

2015-05-10 Notebook on Github

Github now renders notebooks and do not show the raw text by default: Features ou modèle. It is still a little bit slow but why did I spend some time to convert them? I wonder.

2015-04-24 Use javascript tools in your notebook

This is a reason why I do like notebooks. It is more than a static page. Many tools in javascript can be added to the page. The first example is about visualizing the differences between two files. I looks like that:

It is available with pyensae, more details here at A magic command to visualize differences between two files in a notebook.

The second example is about using Scratch from a notebook with Snap!. The code may be slow but the result is quite nice: Scratch dans un notebook.

2015-03-26 Drawing in a notebook

My plan was quite simple : create a kind of small window in a notebook where I can click and mark some points. Once it is done, I retrieve the points and I run a simple algorithm to solve the Travelling Salesman Problem.

The notebook is there Voyageur de commerce and the javascript code is generated by the following function: display_canvas_point.

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-16 Form in notebooks (IPython)

Sometimes I need to type some credentials to access a remote machine from my notebook. I could write them in a cell but then I would need to remove them from the notebook to avoid sharing them by negligence. I was using a simple fonction showing a window tkinter, a pop up. But this solution only works if the notebook server is local. When it is remote, the pop up windows appears on the remote machine and I cannot see it.

IPython allows javascript functions to execute some Python instructions which impact the workspace. All I had to do was to print a form in the page with some javascript. The result can be found here : Having a form in a notebook.

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.


-->

Xavier Dupré