Happy Friday everyone,
This week I’d like to shed some light on the recently introduced IPython Notebook integration in latest PyCharm 4 which was announced a couple of weeks ago:
This feature is considered to be the most important among other cool features that appeared in the latest release, and there is a reason behind it – IPython Notebook is very popular computational environment, and is an extremely useful solution for a wide range of tasks. There is no need to explain how great it is for scientists and data analysts and how convenient it is for learning programming or just showing off some topics or code snippets complemented with texts, graphics, mathematics and plots. It works great for so many people!
The PyCharm team is committed to make great things even better and to provide an extra value for Python programmers at large, so we eventually decided that we can integrate with IPython Notebook and deliver the solution that combines the advantages of IPython Notebook with extra benefits that the most intelligent Python IDE can offer.
Shortly, PyCharm allows you to open and modify *.ipynb files and run them using a standard IPython Notebook kernel. So lets take a look on how it works inside PyCharm.
Setting things up
Consider you already have IPython Notebook files somewhere on your filesystem and would like to work with them using PyCharm. For that, just open the directory containing the files with File | Open when using PyCharm:
Note: With PyCharm you can create new *.ipynb files from scratch. In this example I use File | Open for simplicity.
After that you’ll be able to open the files for editing from the Project View:
To make things working, you first need to specify the project interpreter that will be used for running the code in your *.ipynb files. You can do it in Settings(Preferences for Mac OS) | Project | Project Interpreter. Here you’ll need to check the desired interpreter by choosing from the list of autodetected interpreters or discover it manually. PyCharm also helps you to quickly create virtual environments and manage them. When you’ve selected the right interpreter or virtual environment please make sure you have all the necessary packages installed. For my demo, I already have IPython installed on the virtual environment with other dependencies necessary for IPython Notebook. In case some packages are not installed, please use the integrated package manager to install what is needed:
Now we’re all set and ready to start coding with IPython Notebook. Click on the cell and then click on the run icon in the special IPython Notebook toolbar right on top of the editor:
PyCharm will offer to start the IPython Notebook Kernel automatically and will provide you with an URL where the IPython Notebook kernel will run:
Click OK and in short time you’ll be notified that IPython Notebook started at the URL provided:
From this point you can work with IPython Notebook as usual. PyCharm supports all the basic functionality of ordinary IPython Notebook. The latest format of IPython Notebook files is also supported. You can add new cells, cut and paste them, run arbitrary cells, and change their type. We’ve tried to preserve the similar behavior of ordinary IPython Notebook as much as possible – you can edit and review mathematical formulas in LaTeX, output plots and different graphics, and do other usual actions:
In this blog post I’m not going to cover each aspect of the IPython Notebook integration – instead, I’ll answer the 2 most frequent general questions about this new functionality:
What’s the reason to use PyCharm over classic IPython Notebook?
The main advantage is that PyCharm brings the intelligence and all the additional advantages of an IDE when working with IPython Notebook files. That means you get a code autocompletion, error detection, on-the-fly code fixes and suggestions, navigation and refactorings, local history, VCS support, and a lot more. So basically you get all the neat stuff that makes any developer who uses PyCharm more productive:
There’s also a number of extra features that are not present in classic IPython Notebook, but will be implemented in future versions, like running all cells in one click.
What’s not supported yet?
There is a number of IPython Notebook features that are not supported yet, like interrupt/reload kernel actions, html injections, export to .py files, and some other. After releasing the first version of IPython Notebook integration, we’ve got a bunch of suggestions, bugs and feature requests in our issue tracker. And we’re planning to significantly improve this integration for the next version of PyCharm.
I’d like to encourage you to start using the IPython Notebook integration right away and if you have any problems or suggestions, please file them to our tracker. It’ll help us fix the problems and implement new features even faster.
And here’s some more great news: IPython Notebook integration is supported in PyCharm Community Edition, which means everybody can use it for free!
See you next week!