Atom’s Hydrogen for writing data science projects with Python

M. Rake Linggar A.
Towards Data Science
4 min readMay 2, 2020

--

Whenever I want to write Python code, whether it’s for testing or deployment purposes, I will just open up Jupyter Notebook and start writing. And why not, right? It’s free, open-source, and everyone seems to love it (for example).

And if your company wants to deploy your code on their production environment, you can just use Anaconda Enterprise to do it.

Deploying Jupyter Notebooks in Anaconda Enterprise
Deploying Jupyter Notebooks in Anaconda Enterprise

But, if you need to write Python modules in your project, it can be less than ideal to write and test the module in Jupyter, save it as Python file, and then including it in your main Jupyter notebook and all that.

Plus, the downside of deploying with Anaconda Enterprise? — well….

Google result for Anaconda enterpise cost
Google result for Anaconda Enterprise’s cost

Which is why I looked for an alternative tool. One that can save the hassle of writing production, modular codes, but in which I can still run codes line by line, and also display the data and variables inline.

In comes Hydrogen package for Atom!!!

What is Hydrogen?

Well, like the tagline in the official documentation says

… All the power of Jupyter kernels, inside your favorite text editor.

And so far, it is true and I’m loving it on my MacOS 10.15. It turns your Atom text editor into a Jupyter-like notebook! Plus Atom is a lightweight text editor with plenty of packages to make it an awesome code editor.

Source: Hydrogen official page

This post will walk you through the steps and workarounds to the issues I’ve faced (and some will likely face as well) during installation on MacOS 10.15.

1. Install Atom

This is, of course, a very easy step to do. Just head over to https://atom.io and download the latest version of Atom. Once downloaded, simply copy and paste the Application file to your, well, Applications folder.

“Then just double click to open it, right?” — Well, not really.

Many Mac users, including myself, found that we cannot open the editor, and were greeted with a message like this.

“Atom 2” can’t be opened because Apple cannot check it for malicious software.
This software needs to be updated. Contact the developer for more information.

But don’t worry.

Just right-click the Application file, and then click “Open”.

2. Install Hydrogen Package

Click on Atom > Preferences > Install > type “hydrogen” and click Install.

Install Hydrogen package
Install Hydrogen package

Once it is done, you will need to install the kernels for Python, otherwise, Hydrogen will not work. Open up your Terminal, and type in the following code.

python -m pip install ipykernel
python -m ipykernel install --user

This will install the IPykernel, which is a kernel for Python so that Hydrogen can make Atom execute Python code like how Jupyter does.

Once it is done, restart Atom, and you will be able to run your code line by line and even display your pandas data frames and other visuals you normally make in Jupyter. To see the command shortcuts, you can check it on Packages > Hydrogen and there you will find the list of shortcuts you can use. You’ll find they are quite similar to those in Jupyter.

Hydrogen shortcuts
Hydrogen shortcuts

To run only a selection of lines, just select which line(s) of code you want to execute and press the Run shortcut.

Awesome, right?

To see the full set of Hydrogen’s capabilities, you can check them on the official page.

Plus — Autocomplete

Lastly, it wouldn’t be much of an editor if there are no autocomplete.

Hydrogen already provides an autocomplete function, but when I tried it, several variables or built-in Python functions were not shown. Therefore I recommend you add the autocomplete-python package.

Click on Atom > Preferences > Install > type “autocomplete-python”. and click Install.

If you find some troubles in autocompleting basic Python keywords and variables, it may be that the grammar file is not copied correctly. To fix it, you can try the following code in your Terminal.

cd ~/.atom/packages/autocomplete-python/lib/jedi/parser
cp grammar3.6.txt grammar3.7.txt

Final words

Hope this post is useful and that everyone has a better time writing complex, modular machine learning, data preprocessing, or data analysis codes. Especially during these hard times due to the Covid-19 pandemic.

--

--

Love anything data-related (especially programming), travel, movies, and gaming.