Set up Atom for a Python Programming Environment

Atom is an open source text editor developed by engineers at GitHub. A great text editor is at the core of writing and documenting good code. In this How-To guide you will learn how to set up Atom on a Mac to make coding in Python easy and streamlined.

Prerequisites

To install Atom and begin customizing it for a Python on environment, you’ll need the following:

  • Internet connection

What will be covered?

  1. Installing Atom
  2. Installing packages
  3. Customizing Atom’s default settings

What packages will we install?

Package Function
Script package Runs programming languages within Atom
Autocomplete package Gives word and syntax suggestions as you type
Minimap package Provides a zoomed-out view of an entire file
Python-autopep8 package Formats code base according to Pep 8 standards
Python Linter-flake 8 Checks for errors in the code base

Install Atom

Go to http://atom.io/ and follow the installation instructions.

Disable default welcome windows

Two welcome windows appear every time Atom is opened.

To disable this feature, uncheck the Show welcome guide when opening Atom box.

Result: The default welcome window will not appear each time Atom is opened.

video

Install packages

Installing packages are the heart of customizing and configuring Atom.

Install packages by following these steps:

  1. Click Atom > Preferences > Install.

  2. Click Package next to the search bar.

  3. Type the package name into the search bar.

Result: You are now familiar with the process for installing packages.

video

Install Script package

The Script package allows you to run a variety of programming languages within Atom.

  1. Click Atom > Preferences > Install.

  2. Click Package next to the search bar.

  3. Type Script into the search bar.

  4. Exit the Settings windows after installing.

Result: You can now run Python within Atom. On a Mac the hotkey is cmd-i

video

Change Python version Script uses to run Python

Script will use the default Python version on your Mac, which might Python 2. If you’ve downloaded Python 3, you can use Python 3 to run your scripts. To download Python 3, go here: https://www.python.org/

  1. Click Atom > Preferences > Packages.

  2. Type Script into the search bar.

  3. Click Settings.

  4. Click View Code.

  5. Click Scripts > lib > Grammars > python.coffee.

  6. Under Selection Based and File Based type a ‘3’ after python.

  7. Save the file by pressing cmd-s or File > Save.

  8. Close Atom and the reopen it.

Result: You’re now using Python 3 to run scripts in Atom

video

Result: You can see the Python version in the console output.

video

For a more in depth video on this process, go here: Change Python 2 to Python 3 in Atom

Change Script’s hotkeys

There are many ways to run a Python script, but the easiest way is to use hot keys.

The default hotkey is cmd-i. I think cmd-l is a little easier.

  1. Click Atom > Preferences > Packages.

  2. Type Script into the search bar.
  3. Click Settings.

  4. Click View Code.

  5. Click Scripts > keymaps > scripts.cson.

  6. Change the letter after cmd to your preference.

  7. Click File > Save.

  8. Close Atom and then restart it.

Result: Your new hotkey will run your script.

video

Here is a list of all the ways to run scripts in Atom

Command macOS Linux/Windows Notes
Script: Run cmd-i shift-ctrl-b If text is selected a “Selection Based” is used instead of a “File Based” run
Script: Run by Line Number shift-cmd-j shift-ctrl-j If text is selected the line number will be the last
Script: Run Options shift-cmd-i shift-ctrl-alt-o Runs the selection or whole file with the given options
Script: Run with profile shift-cmd-k shift-ctrl-alt-b Runs the selection or whole file with the specified profile
Script: Close View esc or ctrl-w esc Closes the script view window
Script: Kill Process ctrl-c ctrl-q Kills the current script process

Install file-icons package

Having recognizable icons associated with files makes scanning a large repository easy.

  1. Click Atom > Preferences > Install.

  2. Click Package next to the search bar.

  3. Type File icon name into the search bar and press Return.
  4. Click Install.

Result: Icons are not associated with your file extensions.

video

Install minimap package

Minimap provides a zoomed-out view of your file in the upper-right corner of Atom’s screen. This is nice when working with long files in order to move between parts of the code quickly.

  1. Click Atom > Preferences > Install.

  2. Click Package next to the search bar.

  3. Type minimap into the search bar and press Return.

  4. Click Install.

  5. Choose between Jedi and Kite (I’ll choose Jedi since there’s no signup.)

Result: Minimap is now installed, making it easy to navigate long files.

video

Install autocomplete package

Autocomplete offers a variety of function and method suggestions when writing code. These suggestions can increase your coding speed.

  1. Click Atom > Preferences > Install.

  2. Click Package next to the search bar.

  3. Type autocomplete python into the search bar and press Return.

  4. Click Install.

  5. You’ll be prompted to choose between Jedi and Kite (I’ll choose Jedi since there’s no signup.)

Result: Autocomplete is now installed, which can help increase your coding speed.

video

Install the predawn theme

Themes determine both the look of the user interface looks and the color of the coding syntax. You can change your themes for both the UI and syntax. We’ll change the syntax theme to predawn, a slightly muted color scheme. Explore themes to find one you enjoy.

The predawn theme can be installed by doing the following:

  1. Click Atom > Preferences > Install.

  2. Click Themes next to the search bar.

  3. Type predawn into the search bar and press Return.

  4. Click Install for predawn-syntax.

  5. Click Themes on the left navigation bar.

  6. Click the Syntax Theme drop down menu and choose Predawn.

Result: Your syntax colors have changed and are now based on the predawn stylesheet.

video

Install Python-autopep8 package

The Python autopep8 package formats your Python code according to Pep 8 standards.

You can learn about Pep 8 here: https://www.python.org/dev/peps/pep-0008/

  1. Click Atom > Preferences > Install.

  2. Click Package next to the search bar.

  3. Type pep8 into the search bar and press Return.

  4. Choose python autopep8

  5. Click Install.

  6. Click Settings and scroll to the bottom.

  7. Copy the line “pip install autopep8”.

  8. Open a terminal window.
  9. Paste the pip install line “pip install autopep8” into your terminal window. If the error pip command not found appears, type pip3 install autopep8.

  10. Exit the terminal window after the installation.

  11. Click the box Format On Save in the settings pane. This formats your files to the Pep 8 standards every time you save.

Result: Your Python files will be formatted according to the Pep 8 standards every time you save.

video

Install linter-flake8

Linter-flake8 shows errors in your code base, which helps debugging before you run your code.

  1. Click Atom > Preferences > Install.

  2. Click Package next to the search bar.

  3. Type linter flake 8 into the search bar and press Return.

  4. Choose linter-flake8

  5. Click Install.

  6. Click Yes on the pop-up menus as they appear to install dependencies.

  7. Click Settings and scroll to the bottom.

  8. Copy the line “pip install flake8”.

  9. Open a terminal window.
  10. Paste the pip install line “pip install flake8” into your terminal window. If the error pip command not found appears, type pip3 install autopep8.

  11. Exit the terminal window after the installation.

Result: You can now see the error messages by clicking the orange ‘!’ in the bottom-left.

video

Customize Atom’s default settings

There are a number of settings that change the editor.

We’ll make the following changes to the editor.

Setting Functionality
Font size Changes font size
Scroll past end Allows scrolling past the end of the document
Show indent guide Shows which indents line up in code blocks
Tab length Sets default tab spacing
Console font and output Changes the font size and color of the console output

To start making changes to the editor, follow these instructions:

  1. Go to Preferences > Editor

  2. Scroll down and make the following changes:

    • Change Font Size to 16.
    • Click the box Scroll Past End.
    • Click the box Show Indent Guide.
    • Change Tab Length to 4.

Result: Your editor will be changed according to those values.

video

Change console font output size and color

Changing the console font output size and color makes it easier to view your console results.

  1. Click Atom > Preference.

  2. Click Themes.

  3. Click Your stylesheet.

  4. Scroll to the bottom and paste the following code in:

.script-view .line {
  font-size: 16px;
}
.script-view .panel-body pre {
  color: white
}

.script-view .-linked-path {
  color: red
}
  1. Click File > Save.

  2. If you want to change the color or font size, change the values next to font-size and color.

Result: Your console output font size and color have changed.

video

Push to GitHub from inside Atom

If you use GitHub to host your code, Atom makes it easy to make commits, push, and pull.

  1. Click View > Toggle GitHub Tab

  2. Click the file icon in the bottom-right corner. You can now see the familiar window to stage, commit, push, and pull.

Result: You can now use GitHub within Atom

video

You’re done! Congratulations! Now it’s time to write some great code!