Setting Up a Python Environment in Atom

Ed Haracz
5 min readJan 2, 2020

--

Using a text editor, such as Atom, can be very can be a very efficient way to write Python code. However, using a text editor can become frustrating when you want to run your code, view a DataFrame or display a plot. This does not have to be the case. This blog is an overview of how to set up Atom for a Python environment.

Step 1: Checking Your Python Version

To get the most out of Atom your computer needs to be running Python 3. To check this simply open your Terminal, type in “python”, and hit enter. The result should look something like this:

If your computer’s default is not running Python 3. Corey Schafer has a great video walking you through how to change it.

Step 2: Download Atom

Go to Atom’s Website and click on download.

Step 3: Packages

Now that you have Atom on your computer it’s time to download some packages to allow you to run code within the text editor. To do this follow these steps:

  • Atom (on a Mac it will be in the top left corner by the Apple icon)
  • Preferences
  • Install

You should now see something like this:

There are two main packages that you want to install to begin with. The first is “script” and the second is “Hydrogen”. Type them into the search bar and install them. Script allows you to run code internally within the text editor. Hydrogen actually connects to Jupyter kernels and allows you to use Atom in a similar way, including displays of more advanced objects. The documentation for Hydrogen can be found by clicking this link.

Step 4: Changing Script to Run Python 3

Just like your computer in general, this script package in Atom needs to run Python 3 by default to get the most out of the text editor. The steps to do this are as follows:

  • Atom
  • Preferences
  • Open Config Folder
  • Packages
  • Script
  • Lib
  • Grammers
  • python.coffee

You should now see a display similar to the image above. What we want to do here is find ‘python’ under both ‘Selection Based’ and ‘File Based’ and simply change it to ‘python3’. The image above shows what it should look like after you have changed it. Save your changes and restart Atom to allow the changes to kick in.

Step 5: Running Basic Python Code

With these steps complete you are now able to run basic Python code in Atom. There are two ways to get started. You may either open Atom and in the bottom right corner click on “Plain Text” and change the language to “Python” or you can save the file you want to work in with a “.py” at the end and Atom will automatically know you are writing Python code.

Once you have done this, write some code as a test. The keyboard shortcut “Command I” will run the code.

Step 6: Hydrogen

Now that you’re running code in Atom, it’s time to get a little more advanced using the Hydrogen package. You can start a file the same as we did previously but for the sake of testing it may be better to open up a Python file that has some DataFrames or plots already within it and see if they work in Atom. To do this, open up your terminal, CD into the directory containing the files you would like to work on and run the command “atom .” like below.

This will open the entire directory on the left-hand side of the text editor. Double click the specific file you would like to work on and it will open. Now you are ready to start playing around with Hydrogen. The main keyboard shortcut that I use is “Shift Enter”. This runs the line of code that you are on. There are other shortcuts as well and they can be seen in the image below:

**Note that if you plan to use Hydrogen to run a line of code that relies on a line above you must use Hydrogen for the proceeding line as well. **

Tying all of this together you can now use Atom as you would a Jupyter notebook.

Further Information

Themes

Atom, along with many text editors, allows you to customize the look and feel of it’s environment. You can change the theme of your text editor to your tastes. To do this follow the instructions from Part 3 and change “Packages” to “Themes”. This will allow you to download new looks for Atom. Note that they are separated by “UI” which is the overall/background theme, and “Syntax” which refers to the coloring of the text and text area. This link may be useful in finding some themes that suit your tastes.

Additional Packages

What follows is a list of additional packages that may improve the functionality of Atom or help you write better/cleaner code. Feel free to use or disregard them depending upon your personal preferences:

  • Minimap
  • auto-complete python
  • file-icons
  • linter-flake8
  • python_autopep8
  • platformio-ide-terminal

References:

--

--