CSC148 Software Guide, Summer 2016

This offering of CSC148 uses two important pieces of software: the Python programming language, and an Integrated Development Environment (IDE) called PyCharm to use to write Python code.

This guide will take you through the process of installing the necessary software on your machine, and then getting everything configured properly with the provided CSC148 files. This is the first time we're using PyCharm in this course, and there are bound to be hiccups. Let us know as soon as possible if you're having difficulties with PyCharm, and we'll help you the best we can, and update the "Troubleshooting & Tips" section at the end of this guide.

If you are on a CDF machine, you can skip to Part 2 - the software is already installed on those machines for you, and you can, if you wish, complete all of your work in this course on them.

Part 1 - Installation

  1. Go to https://www.python.org/downloads/ and download the latest version of Python, and then install it. You are required to use either Python 3.4.3 or higher, and will almost certainly run into some trouble if you're using Python 2 to 3.3. We recommend not changing any of the default settings during installation.
  2. Go to https://www.jetbrains.com/pycharm/download/ and download the Community Edition of PyCharm. Again, we recommend keeping the default settings.

Part 2 - Configuring PyCharm

PyCharm is a very powerful software development tool that's used by industry professionals around the world. It's very powerful, but in fact a little too much to handle for us when we're getting started. This part will set you up with a set of folders to use for your work in CSC148, as well as simplify the configuration of PyCharm to make it easier for beginners to use.

  1. Download the file at this link.
  2. Extract the contents of the file into any folder you like, such as your "Documents" folder. (On CDF, you can right-click on the tar file and select "Extract -> Extract Archive To...". You should see a new "csc148" folder appear at your target location.
  3. Start PyCharm. (On CDF, this is in the Start Menu under "First Year CDF".)
  4. Select "Open". Navigate to your new csc148 folder, select it and press OK.
  5. Select "File -> Import Settings...". Navigate to your csc148 folder, and inside there should be a "settings.jar" file. Select it and press OK.
  6. Make sure all components are selected, except: if you are using a Mac, DESELECT "Key maps". Press OK.
  7. PyCharm will restart. You may need to restart it one more time, if it asks you to.

At this point, you should see the open CSC148 project in PyCharm, along with a relatively simple menu if you are on CDF, you should be done at this point. If you're using your own machine, you'll need to select which version of Python you want to use before doing anything else (PyCharm will likely be displaying an error). To fix this:

  1. Press "Ctrl + Alt + S" (I believe it's "⌘ + ," on Macs) to access the Settings window. Or, look under File -> Settings (or PyCharm -> Preferences on Macs) Then go to Project: csc148 -> Project Interpreter.
  2. In the dropdown, select the version of Python you installed. If your version doesn't appear, consult the steps below.
  3. Press OK, then restart PyCharm.

Update - finding your Python interpreter

The Python interpreter is the program on your computer which is actually able to run Python programs. Here are some tips on how to get PyCharm to find it, if it doesn't automatically:

  1. In the same dropdown from step 9 above, click on "Show All".
  2. Click on the "+" icon on the top-right of the new window, and select "Add Local".
  3. Now you have to find a program called either "python" or "python3" on your computer. This is the Python interpreter. Its location will depend on where you installed Python, but by default you should look for...
    • Windows: either C:\Python34\python.exe or C:\Python34\python.exe
    • Mac: /usr/local/bin/python3. (If you see usr/local/bin/python this likely refers to a version of Python 2 on your computer, which you cannot use for this course.)
  4. After you've selected the Python interpreter, click OK and then select it in the other windows.
  5. Restart PyCharm.

If you had trouble with the above steps, ask for help!

Part 3 - Working with PyCharm

That's it! You can play around with the settings by pressing "Ctrl + Alt + S" (Mac: "⌘ + ,"), changing the appearance, keyboard shortcuts, etc.

We have configured PyCharm to run real-time "inspections" on your code, which will detect things like syntax errors and highlight them as you type. PyCharm will also highlight any style errors which don't agree with PEP8, the official Python style guide. Your assignment submissions will be checked for style, so take advantage of this and get in the habit of fixing style errors right away.

Finally, the other nice thing about PyCharm is it will perform auto-completion for you when you use "dot notation" to access attributes or methods of an object. We'll take advantage of this feature in CSC148 by providing PyCharm with type hints so that it gives us relevant suggestions. Read through this page: https://www.jetbrains.com/pycharm/help/type-hinting-in-pycharm.html. PyCharm accepts a few different kinds of syntax; we'll use one particular kind in this course, which you'll see on all of the code in lectures, labs, and assignments.

Troubleshooting & Tips

Here are some common problems (and their solutions) that come up in PyCharm.

I have a file blah.py, but when I try to write "import blah" PyCharm can't find the module.

All folders with a blue icon in the Project view are source folders, meaning they're automatically searched for Python modules. Almost all of the folders we gave you are source folders already.

If you create your own folder, you'll need to mark it as a source folder yourself. To do this:

  1. Right-click on the folder in the Project view.
  2. Select "Mark Directory As -> Sources Root"
  3. Restart PyCharm. (I know this is a pain,

I'm getting an error message about line endings. The file looks fine, what's going on?

Different operating systems (Windows, OSX, Linux) use different ways to represent line endings. Since you might use a different OS at home than on CDF, or from your partner, it's important to make sure the line endings are consistent. In this course, we'll always use Unix separators ().

To convert your files to use Unix separators, go to "File -> Line Separators -> LF - Unix and OS X ()".

My Python console is missing!

By default it should appear, but you can always start it by going to "Tools -> Python Console..."

I get an error when I try to start the Python console!

It's likely that your Python interpreter isn't configured properly. Check steps 8-10 in Part 2.

I can't for the life of me figure out how to run a file!

Yeah, this is one of the complexities of many IDEs. Right-click on the file you want to run, then select "Run ". The next time, you can press Shift + F10, which runs the most recently run module.

How can I load my code in module blah.py into the console?

Two ways:

  1. In the console, type "from blah import *".
  2. Or, select all the code, then right-click on it and select "Execute Selection in Console".

For more repeated testing, either make use of the if __name__ == '__main__' block or a separate unit test file.

I'm getting a "Cannot read scheme CSC148.icls..." error

I haven't been able to figure out why this happened, but there's an easy way to fix it:

  1. Open the Settings window, and go to "Editor -> Colors & Fonts".
  2. Change the color scheme to a different one, e.g. "Default".