These exercises are meant to get you set up with a Python interpreter, a text editor, and GitHub.
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:
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.
Click "I want Python 3.4"
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.
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.
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.
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.
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.
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.
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.
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!
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!!
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.