paint-brush
Setting up Atom as a Python IDE [A How To Guide]by@DavidDataScience
98,924 reads
98,924 reads

Setting up Atom as a Python IDE [A How To Guide]

by DavidFebruary 13th, 2020
Read on Terminal Reader
Read this story w/o Javascript

Too Long; Didn't Read

Setting up Atom as a Python IDE [A How To Guide] The guide shows how you can setup and maintain a python friendly development environment from within Atom. In a separate article I (will) show how to setup Microsoft Visual Studio Code in a similar manner. The guide is tested and valid for the latest version of Atom 1.40-40-Python 3. (It may work for earlier versions of Atom, but untested.) The guide includes a Linter Package (Source Code Checker) and a Script Package.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - Setting up Atom as a Python IDE [A How To Guide]
David HackerNoon profile picture

In this article, I demonstrate how you can setup and maintain a python friendly development environment from within Atom.  Ideally, a developer wants to reduce the amount of window/application switching as much as possible and create repeatable workflows. 

Contrary to the above parody cartoon, Atom is a respectable editor and keybinding plugins are available for those of us that grew up with Emacs and Vim so that we can have a mouse-free coding experience.

Atom was developed initially from with Github, but by it’s open-source and extensible nature, a strong community that provides support and additional plugin functionality, it has become a very powerful – but free – tool for development.

I use Atom primarily for Python, Julia, shell script and web-development. In a separate article I (will) show how to setup Microsoft Visual Studio Code in a similar manner.  Code is also open-source, free, and supported by a large community, and it has advantages if you also code for various compilers and proprietary databases. 

Note: Towards the end of this article I discuss how you can automate the saving of a list of all of your plugins so that you can reinstall them as a group later, keep in a code repository, or migrate to a new development machine.  Myself, I keep my configuration in the cloud, so I can continue to work at a client location with a predictable setup.

These instructions are tested and valid for

Atom 1.40
and
Python 3
and up. (It may work for earlier versions of Atom, but untested.)

Steps:

1. Download Atom

“Atom is a free and open-source text and source code editor for macOS, Linux, and Microsoft Windows with support for plug-ins written in Node.js, and embedded Git Control, developed by GitHub. Atom is a desktop application built using web technologies.” https://flight-manual.atom.io/getting-started/sections/why-atom/

You can use Atom's UI to install the plug-ins listed below using Atom's Settings View: just type

ctrl +
(on Linux or a PC), and 
cmd +
(on a Mac).

Alternatively to bring up the Settings View, you can click on the Install tab, and type the package name you want to install into the Search packages search box.

For the rest of us who actually like to use the terminal window, I provide shell commands below.

2.   Download a Linter Package (Source Code Checker)

“Linter is a base linter provider for the hackable Atom Editor. Additionally, you need to install a specific linter for your language. You will find a full list on atomlinter.github.io.

It provides a top-level API to its consumer so that they can visualize errors and other types of messages with ease.”

https://atom.io/packages/linter

or, on the command line:

$ apm install linter

Now we also need to download a language specific linter plugin (I like flake8, but there are choices listed on the atomlinter.github.io page as above:

https://atom.io/packages/linter-flake8

or, on the command line:

To use this plugin flake8 will need to be installed on your system. If it is not already installed, you can install flake8 by typing the following in a terminal:

$ pip install flake8
$ apm install linter-flake8

3. Download a Python AutoComplete Package and AutoFormatter

“Python completions for packages, variables, methods, functions, with their arguments. Powered by your choice of Jedi or Kite.”  Jedi is a locally based library, and thus I myself prefer that one over Kite, which requires an online library.

https://atom.io/packages/autocomplete-python

or, on the command line:

$ apm install autocomplete-python

“Uses autopep8 installed to format python code according to pep8 guidelines”

https://atom.io/packages/python-autopep8

or, on the command line:

$ pip install autopep8
$ apm install python-autopep8

4. Download a Script Package

“Run scripts based on file name, a selection of code, or by line number.” This is super useful for testing your code from within Atom instead of going to a different terminal window, and it is powerful because it is selection-based, which means you can run snippets versus whole files.

https://atom.io/packages/script

or, on the command line:

$ apm install script

5. Download a File-Icons Package

“File icons similar to the vscode-icons pack for Visual Studio Code (https://github.com/vscode-icons/vscode-icons) and built off of the logo-file-icons pack (https://atom.io/packages/logo-file-icons) with tweaks and
additions.  Tree view ui tweeks to closer match that of visual studio code.” 

As I tend to use both Visual Studio Code and Atom, this helps me maintain consistency, and I like them better than the Atom defaults.

https://atom.io/packages/atom-file-icons

or, from the command line:

$ apm install atom-file-icons

6.   Download a Syntax Highlighting Theme

“A syntax theme for Atom Material UI. Inspired by Mattia Astorino's  SublimeText theme.“

https://atom.io/packages/atom-material-syntax

or, from the command line:

$ apm install atom-material-syntax

7. Download and Install Minimap

The Minimap package displays a Minimap preview of your file on the right hand side of your editor.  The minimap-git-diff and minimap-highlight-selected plugins are also useful.

https://atom.io/packages/minimap

or, from the command line:

$ apm install minimap
$ apm install minimap-git-diff 
$ apm install minimap-highlight-selected 

8.   Download and install a Jupyter Notebook Plugin

“A package that works like the Jupyter Notebook, but inside Atom. It's registered as an opener for .ipynb files — try opening one!"

https://atom.io/packages/jupyter-notebook

or, from the command line:

$ pip install jupyter jupyter_kernel_gateway
$ apm install jupyter-notebook

Alternatively, you can look at the Hydrogen package:

Hydrogen runs code interactively, allows you to inspect data, and plot. All the power of Jupyter kernels, inside your favorite text editor. It supports Python, R, JavaScript and other Jupyter kernels.

Checkout the Documentation and Medium blog post to see what you can do with Hydrogen.

9. Improve version control support for Atom

Because I work for several clients, I am often switching between Github, gitlab and Bitbucket for different repositories. Please look search for the following at https://atom.io/packages:

  • git-control
  • git-plus
  • git-blame
  • git-time-machine
  • gitlab
  • open-on-bitbucket

10. Using version control (or cloud drives) for configuration portability

Use to version control your Atom config file, and any other config files that you may have.

Linux:

~/.atom/config.cson

Windows:

%USERPROFILE%\.atom\config.cson
  [or commonly]
C:\Users\{name}\AppData\Local\atom\config.cson

You can then host and clone your Git repository on Github, gitlab, Bitbucket, etc., and retrieve it on other computers simply by running:

$ git clone https://github.com/{username}/{repo}

As with any other source-control repository, you can then keep it up to date (to upload changes) and (to download changes).

git push
and
git pull

As mentioned in the note at the beginning of the article, in order to track a common list of installed packages, at the terminal shell execute:

$ apm list --installed --bare > ~/.atom/package.list

And then add that file to you source-controlled Git repository also.

To install the packages automatically back into a fresh installation of Atom:

$ apm install --packages-file ~/.atom/package.list

An example of my

package.list
file is as below:

Conclusion

In this article, I demonstrated how you can setup and maintain a python friendly development environment from with Atom (https://atom.io/). 

As a developer who wants to reduce the amount of window/application switching as much as possible and create repeatable workflows, I hope that you find this equally useful. I look forward to your comments and suggestions for improvements!

@DavidDataScience

Agree or disagree with some of the ideas presented in this article? Let
us know your thoughts on Digg.

Looking for more coding articles? Subscribe to our newsletter in the footer below!