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?
- Installing Atom
- Installing packages
- 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.
Install packages
Installing packages are the heart of customizing and configuring Atom.
Install packages by following these steps:
-
Click
Atom
>Preferences
>Install
. -
Click
Package
next to the search bar. -
Type the package name into the search bar.
Result: You are now familiar with the process for installing packages.
Install Script package
The Script package allows you to run a variety of programming languages within Atom.
-
Click
Atom
>Preferences
>Install
. -
Click
Package
next to the search bar. -
Type
Script
into the search bar. -
Exit the Settings windows after installing.
Result: You can now run Python within Atom. On a Mac the hotkey is cmd-i
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/
-
Click
Atom
>Preferences
>Packages
. -
Type
Script
into the search bar. -
Click
Settings
. -
Click
View Code
. -
Click
Scripts
>lib
>Grammars
>python.coffee
. -
Under Selection Based and File Based type a ‘3’ after python.
-
Save the file by pressing cmd-s or
File
>Save
. -
Close Atom and the reopen it.
Result: You’re now using Python 3 to run scripts in Atom
Result: You can see the Python version in the console output.
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.
-
Click
Atom
>Preferences
>Packages
. - Type
Script
into the search bar. -
Click
Settings
. -
Click
View Code
. -
Click
Scripts
>keymaps
>scripts.cson
. -
Change the letter after
cmd
to your preference. -
Click
File
>Save
. - Close Atom and then restart it.
Result: Your new hotkey will run your script.
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.
-
Click
Atom
>Preferences
>Install
. -
Click
Package
next to the search bar. - Type
File icon
name into the search bar and pressReturn
. - Click
Install
.
Result: Icons are not associated with your file extensions.
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.
-
Click
Atom
>Preferences
>Install
. -
Click
Package
next to the search bar. -
Type
minimap
into the search bar and pressReturn
. -
Click
Install
. -
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.
Install autocomplete package
Autocomplete offers a variety of function and method suggestions when writing code. These suggestions can increase your coding speed.
-
Click
Atom
>Preferences
>Install
. -
Click
Package
next to the search bar. -
Type
autocomplete python
into the search bar and pressReturn
. -
Click
Install
. -
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.
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:
-
Click
Atom
>Preferences
>Install
. -
Click
Themes
next to the search bar. -
Type
predawn
into the search bar and pressReturn
. -
Click
Install
for predawn-syntax. -
Click
Themes
on the left navigation bar. -
Click the
Syntax Theme
drop down menu and choosePredawn
.
Result: Your syntax colors have changed and are now based on the predawn stylesheet.
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/
-
Click
Atom
>Preferences
>Install
. -
Click
Package
next to the search bar. -
Type
pep8
into the search bar and pressReturn
. -
Choose
python autopep8
-
Click
Install
. -
Click
Settings
and scroll to the bottom. -
Copy the line “pip install autopep8”.
- Open a terminal window.
-
Paste the pip install line “pip install autopep8” into your terminal window. If the error
pip command not found
appears, typepip3 install autopep8
. -
Exit the terminal window after the installation.
- 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.
Install linter-flake8
Linter-flake8 shows errors in your code base, which helps debugging before you run your code.
-
Click
Atom
>Preferences
>Install
. -
Click
Package
next to the search bar. -
Type
linter flake 8
into the search bar and pressReturn
. -
Choose
linter-flake8
-
Click
Install
. -
Click
Yes
on the pop-up menus as they appear to install dependencies. -
Click
Settings
and scroll to the bottom. -
Copy the line “pip install flake8”.
- Open a terminal window.
-
Paste the pip install line “pip install flake8” into your terminal window. If the error
pip command not found
appears, typepip3 install autopep8
. - Exit the terminal window after the installation.
Result: You can now see the error messages by clicking the orange ‘!’ in the bottom-left.
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:
-
Go to
Preferences
>Editor
-
Scroll down and make the following changes:
- Change
Font Size
to16
. - Click the box
Scroll Past End
. - Click the box
Show Indent Guide
. - Change
Tab Length
to4
.
- Change
Result: Your editor will be changed according to those values.
Change console font output size and color
Changing the console font output size and color makes it easier to view your console results.
-
Click
Atom
>Preference
. -
Click
Themes
. -
Click
Your stylesheet
. -
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
}
-
Click
File
>Save
. -
If you want to change the color or font size, change the values next to
font-size
andcolor
.
Result: Your console output font size and color have changed.
Push to GitHub from inside Atom
If you use GitHub to host your code, Atom makes it easy to make commits, push, and pull.
-
Click
View
>Toggle GitHub Tab
-
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