Atom Editor Setup For Python

First Install For Your OS

Atom on Mac

Atom was originally built for Mac and should be a simple setup process. You can either hit the download button from the atom.io site or you can go to the Atom releases page at:

https://github.com/atom/atom/releases/latest

Here you can download the atom-mac.zip file explicitly.

Once you have that file, you can click on it to extract the binary and then drag the new Atom application into your “Applications” folder.

When you first open Atom, it will try to install the atom and apm commands for use in the terminal. In some cases, Atom might not be able to install these commands because it needs an administrator password. To check if Atom was able to install the atom command, for example, open a terminal window and type which atom. If the atom command has been installed, you’ll see something like this:

$ which atom
/usr/local/bin/atom
$

If the atom command wasn’t installed, the which command won’t return anything:

$ which atom
$

To install the atom and apm commands, run “Window: Install Shell Commands” from the Command Palette, (cmd + shift + p), which will prompt you for an administrator password.

Atom on Windows

Atom comes with a windows installer. You can download the installer from https://atom.io or from:

https://github.com/atom/atom/releases/latest

This will install Atom, add the atom and apm commands to your PATH, create shortcuts on the desktop and in the start menu, and also add an Open with Atom context menu in the Explorer.

Atom on Windows
FIGURE 1-2.Atom on Windows

If you just want to download a .zip of the latest Atom release for Windows, you can also get it from the Atom releases page at https://github.com/atom/atom/releases.

Atom on Linux

To install Atom on Linux, you can download a Debian package or RPM package either from the main Atom website at atom.io or from the Atom project releases page at https://github.com/atom/atom/releases.

On Debian, you would install the Debian package with dpkg -i:

$ sudo dpkg -i atom-amd64.deb

On RedHat or another RPM based system, you would use the rpm -i command:

$ rpm -i atom.x86_64.rpm

Atom from Source

If none of those options works for you or you just want to build Atom from source, you can also do that.

There are detailed and up to date build instructions for Mac, Windows, Linux and FreeBSD at: https://github.com/atom/atom/tree/master/docs/build-instructions

In general, you need Git, a C++ toolchain, and Node to build it. See the repository documentation for detailed instructions.

Setting up a Proxy

If you’re using a proxy, you can configure apm (Atom Package Manager) to use it by setting the https-proxy config in your ~/.atom/.apmrc file:

https-proxy = https://9.0.2.1:0

If you are behind a firewall and seeing SSL errors when installing packages, you can disable strict SSL by putting the following in your ~/.atom/.apmrc file:

strict-ssl = false

You can run apm config get https-proxy to verify it has been set correctly, and running apm config list lists all custom config settings.

Edit a Python file and use Atom’s Autocomplete

Let’s start by creating a Python file with:

In the new file, if you type de, you’ll see that it suggests if you want to create a new function. This is because Atom has detected that the file extension is a Python extension.

creaate-function

If you type the Tab key, you’ll see a template for a new function:

create-function-2

Note that you have the fname highlighted. This is because you can now type the name of your function and it will replace  fname. Let’s name our function  product.

Next, if you hit the  Tab key again, the arguments of the function, arg, will be now selected. Just write x, y, as we need two different arguments for our function.

Finally, hit the  Tab key again to select the body of our function, pass, and replace it for our code. The end function should be something like:

Linter for Atom

Linter is an Atom package that provides a top level API so that there is a unification among all the linter atom plugins. This means that all the extra packages that you install, that highlight your code (for example to detect errors) will use a unified method.

To install it, just type:

This package is called linter-flake8 and it’s an interface to flake8. To install it, you need to run:

atom-linter-flake8

If you open Atom and you find an error that says

 The linter binary flake8 cannot be found

process.env.PATH = [‘/usr/local/bin/’, process.env.PATH].join(‘:’)

Moreover, there are Linters for other languages like HTML, CSS or Javascript. You can find a list here.

Further customisation for Python to follow PEP8

Here I’ll show you how you can configure Atom to follow PEP8, the official Python styling guide.

First, open the Atom –> Preferences window.

1. Use spaces instead of tabs.

Scroll down the Settings panel until you see the Soft Tabs option. Make sure it’s checked. This setting will convert tabs into spaces automatically.

atom-settings

2. Set the tab length to 4 spaces

A little below the Soft Tab setting, you”ll see the Tab Length. Set it to 4 spaces.

3. Automatic PEP8 validation.

If you installed the linter-flake8 package discussed in the previous section, you already have automatic PEP8 validation

Keybindings customisation

In the same Preferences panel, you can see the Keybindings menu on the left. There, you’ll find a list of all the default keybindings active in your Atom editor.

However, by default, Atom confirms an autocomplete suggestion with both the Tab and Enter keys. But I only want to use the Tab key.

In order to disable Enter as an autocomplete confirm key, we need to go to the Keybindings menu where you’ll see a link that says your keymap file. Click on that link to open the keymap.cson file.

There, you need to write:

Other Useful Packages

Project manager: a package for saving your projects.

Atom Django: Django support for Atom

Minimap: Displays a small map of the current file on the right side of your document (like Sublime Text by default).

Script: Lets you run python scripts in Atom

Beautifier: Autocorrect your PEP8 lint errors

$ pip install autopep8
$ apm install atom-beautify