PyShop Pre-workshop Exercises


These exercises are meant to get you set up with a Python interpreter, a text editor, and GitHub.

1. Getting Python

Macs come with Python already, but what we want is Anaconda, which includes over 330 of the most used packages, ipython and the ipython notebook. There is a quick start guide available on the Continuum Analytics website, but the general steps are as follows:

  1. Go to the anaconda page in the Continuum shop.
  2. Click the "Download Anaconda" link. NOTE: At this point you face a choice: 2.7 or 3.4. We will use Python 3.4 for this course, but I have experienced some compatability issues (in particular with PyCUDA), so be aware that this may be a problem.

  3. Click "I want Python 3.4"

  4. Click the download link below "Choose your installer..." It should say something like "Windows 64-Bit Python 3.4 Graphical Installer". BE SURE IT SAYS "64-Bit"!!!!! Also, be sure you have a 64 bit processor... if you have a 32-bit you should probably have updated it a decade ago...
  5. When the download is complete, double click the file and follow the on-screen instructions.

You should now be able to open IPython or an IPython Notebook from the command line. Simply type ipython or ipython notebook in a terminal.

2. Getting a Text Editor

This section should be titled getting THE text editor, as it is completely biased. However, having spent time testing several editors, I find that Atom is the most intuitive and the easiest to set up (it also has some nice technical features for the future, but we'll talk about that in class). So this section will cover Atom, but feel free to use whatever editor you like. My second choice would be Sublime Text Editor.

WARNING: Atom cannot run on Windows XP or earlier... sorry! If you are in this situation I would suggest VIM, but it is a true pain so you're on your own.

  1. Go to https://atom.io/.
  2. Click the download installer link.
  3. Open the .exe file you just downloaded and follow the instructions.

Boom! You're done! So easy. Now there are a few extra steps to take to get Atom running great for Python.

First, we are going to set some preferences.

  1. Navigate to Edit > Preferences. From here you can change the settings to your choices.
  2. You MUST turn on "Soft Tabs" and set "Tab Length" to 4. Python does not use braces to delineate functions or loops, but 4 spaces. This makes presentation neater and code easier to read.

Last, we will install a linter to verify that your code meets the community standards in PEP8, the active style guide. NOTE: This step can only be performed after you have installed Anaconda.

  1. Open a terminal.
  2. Install the linter package by typing "atom install linter" or "apm install linter", depending on if you have mac, windows or linux. Try each command and use the one that works in the future.
  3. Next we need to install the flake8 linter package, but this type of third party package management can be a pain in Anaconda. To begin try running the following:

     conda install flake8
     conda install flake8-docstrings
     atom install linter-flake8

If you get no error messages, great! If this doesn't work, you'll need to locate the directory where you installed Anaconda and then run the following:

    cd /path/to/anaconda
    pip install flake8
    pip install flake8-docstrings
    atom install linter-flake8

If you are still having trouble and have tried to ask Google, send me an email and I will try to help.

When you are done you should be able to save a practice file, say practice.py (notice the .py is the file extension for Python scripts) and type some code. The linter will automatically highlight the code and give you warnings for errors and style violations.

3. GitHub

GitHub is ubiquitous in open source software and if you ever want to contribute to a project you will need to be able to use it. GitHub is also a great tool for storing and publishing your own code, as well as tracking changes or even hosting free static html websites. Conclusion: use GitHub!

There is a great tutorial here on how to set up your GitHub account. I suggest you read through that whole article and set up your own GitHub account at www.github.com. The process of setting up git and creating local repos is quite long, so it is more efficient to just send you to the GitHub help here: https://help.github.com/ . You should follow their steps (the site detects your operating system automatically) and try to get set-up yourself. There is also a great page with information on the basic process here: https://guides.github.com/. We will go over in class the main idea behind GitHub, but if you have specific questions please contact me.

Once you have Git installed on your local machine, I encourage you to follow these steps to clone the PyShop repository to your local machine. Once you do this, you can easily check for updates each week and Git will automatically sync for you.

  1. First, fork the repo by navigating to the PyShop repo on GitHub at https://github.com/tyler-abbot/PyShop, then clicking on the "Fork" link in the top right. This should create a repo on your own GitHub account that contains the same files and folders as the master PyShop repository.

  2. Next, you'll need to create a local clone on your home computer. Navigate to your GitHub page for your new fork. It should be something like https://github.com/YOURNAME/PyShop. On the right hand side you'll see a box that says "HTTPS clone URL", just under "Settings". Copy what's in the box or click the "copy to clipboard button.

    Open a terminal or command prompt and navigate to the parent folder where you would like to store your repo. For instance, if you want to store it in a folder titled Users/you/PyShop, type cd Users/you. Finally, use the following command to clone the repository:

     git clone https://the/url/you/copied
    
    

    You now have a local clone!

  3. Now, you'll need to configure the repository to know how to sync. Navigate to the PyShop GitHub page again and copy the clone repository URL.

    Now, open a terminal and navigate into your newly cloned repositor, eg cd Users/you/PyShop. Now type git remote -v. This will display the current "upstream" repository. You want to add the master branch to this. Type the following (I've filled in the url for you, but you can paste the one you got from GitHub if you'd like):

     git remote add upstream https://github.com/tyler-abbot/PyShop.git
    
    

    Check your work by typing git remote -v again. If you now see the upstream listing my GitHub account, success!!

  4. Whenever you would like to sync up your local repository with my master branch, just cd into your local repository and type the following:

    git fetch upstream
    git checkout master
    git merge upstream/master

That should do it. You now have a full Python installation with many packages, a great text editor that will correct your syntax and style in real time, and a local GitHub repository for the course that will automatically sync! If you have problems with any of the steps here, please let me know.