Extra Setup
UTF-8 all the things
Open up your shell and run the following commands to set your default character encoding to UTF-8 (for now we’ll call that: worldwide characters, instead of just U.S.). If you’re typing instead of cutting and pasting, make sure you’re using ».
echo 'export LC_ALL=en_US.UTF-8' >> ~/.bash_profile
echo 'export LANG=en_US.UTF-8' >> ~/.bash_profile
Having matplotlib
play nice with virtual environments
The matplotlib
library has some issues when you’re using a Python 3 virtual environment. The error looks like this:
RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are Working with Matplotlib in a virtual enviroment see ‘Working with Matplotlib in Virtual environments’ in the Matplotlib FAQ
Luckily it’s an easy fix.
mkdir -p ~/.matplotlib && echo 'backend: TkAgg' >> ~/.matplotlib/matplotlibrc
This adds a line to the matplotlib
startup script to set the backend to TkAgg, whatever that means.
Customizing Atom
IDE’s are great (in theory) because they do things like notice typos and help you along with your coding. Luckily, Atom’s claim to fame is that it’s extensible - you can use plugins called packages to add extra functionality. We’re going to follow this guide to customize Atom for Python, making sure we do the following:
1. Ignore that first section about autocomplete
It isn’t important at all! It’s just testing out Atom.
2. Install the linter on your machine
A linter is a tool that lets you know when your code looks a little suspicious. It’s your computer’s way of saying “hey, are you sure you meant to do this?” It’s a great way to fix typos and other mixtakes (or avoid writing them in the first place).
To install a Python linter for Atom, we need to do this in two steps. First, we need to install flake8, which is a weirdly-named Python… thing that powers the linter. We’ll explain what this mysterious pip
is later, too.
If you’re on Windows, you’ll need to go visit http://www.python.org/downloads to download and install Python 3.5. During the installation be sure to check with “Add Python 3.5 to PATH” checkbox. You should even do this if you installed Python in babun - this is a separate Python.
On OS X, open update the Terminal. In Windows, run the cmd command (Command Prompt). Run the following command.
pip install flake8
Take a look at the output that it spits back at you - it probably won’t be anything you can understand, but keep an eye out for words and phrases like Error
, Couldn't...
, or Didn't have permission to...
. If you aren’t sure if it installed correctly, feel free to ask someone near you! TAs and instructors will also be happy to help.
3. Add the plugins to Atom
Open up your Preferences menu in Atom through either Atom
> Preferences
(OS X) or File
> Settings
(Windows). Then click the Install tab on the bottom left. Search for linter-flake8
and click the Install button.
4. Auto-fix the spacing
Click the Settings tab in Preferences and update the Soft Tabs (yes) and Tab Length (4).
5. Stop the enter key from autocompleting
You know how sometimes autocomplete on your phone can be good, and sometimes it can be terrible?
It’s the same with Atom. You usually use the tab key to say “yes, sure, I like your programming-thing suggestion” but by default Atom also has the enter key accept autocomplete. This is terrible when you’re just trying to go down to the next line and ignore the suggestion!
To turn it off, select the Keybindings tab, then click the link that says your keymap file. Scroll down to the bottom and paste the following in.
# Disable Enter key for confirming an autocomplete suggestion
'atom-text-editor:not(mini).autocomplete-active':
'enter': 'editor:newline'
Be sure to save.
6. Install minimap and autocomplete-python
If you have a large file, it’s sometimes hard to know exactly where you’re at. Near the top? At the bottom? Somewhere in the middle? Helpfully,
minimap lets you see where in your code you’re at. You can install minimap by going back to the Install section of Preferences and searching for minimap
(be sure you pick the one with the plain name minimap
, not any of the minimap-plus-other-things plugins).
Do the same with autocomplete-python
.
7. Restart Atom
Now that you’ve installed all of these awesome additions to Atom, you’ll need to restart it for everything to take effect.