# CSC148 Software Guide

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. 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 teaching lab 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 - Software 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 Python 3.5.0 or later, and will almost certainly run into some trouble if you're using Python 2 to 3.4. We recommend not changing any of the default settings during installation.

## 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.

2. Extract the contents of the file into any folder you like, such as your "Documents" folder. (In teaching labs, you can right-click on the tar file and select "Extract -> Extract Archive Here". You should see a new "csc148" folder appear in the current folder.

On Windows, use a program like Winzip to extract the file.
3. Start PyCharm. (On teaching labs, 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, and press OK.
7. PyCharm will restart. You may need to restart it one more time, if it asks you to.
8. In PyCharm, press Ctrl + Alt + 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.
9. Select Python 3.5.2 in the dropdown menu for the Project Interpreter.

If you don't see it in the dropdown, but you're sure you installed it, the jump down to Locating your Python interpreter below.

## Part 3 - Installing Python libraries - your machine only

Skip this step if you're on a teaching lab machine, as they already have these libraries installed.

For this course, we will be using two Python libraries which do not come directly with Python. The easiest way to install them is to use PyCharm:

1. Open the Settings window and go to Project: csc148 -> Project Interpreter.
2. Make sure that the correct version of Python is selected in the dropdown (this should be the same from Part 2).
3. Click on the green + icon, which should be beside or below the list of installed libraries.
4. Search for "python-ta", select it, and press Install Package.

Note: if you get a PermissionError (common on Windows), select the checkbox "Install to user's site packages directory".
5. Repeat steps 3 and 4 for the library "hypothesis".
6. In the list of installed libraries, you should now see both "python-ta" and "hypothesis" (along with a few other libraries that were required in the installation.

## Part 4 - 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've given you a sample file called welcome.py in the csc148 folder - read through it and try to run it.

We have configured PyCharm to run real-time "inspections" on your code, which will detect syntax, logical, and style errors and highlight them as you type. Your exercise and assignment submissions will be checked for style, so take advantage of this and get in the habit of fixing all 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. 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 on the left 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 and try again.

### 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 "Edit -> 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 "Run -> Python Console..."

### I get an error when I try to start the Python console or run a file.

It's likely that your Python interpreter isn't configured properly. Check steps 8-9 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. Open the file you want to run, then go to Run -> Run... and select the file name from the popup menu. 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 Python 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.

### When I import my Python file, my most recent changes aren't used.

This happens when you import a file in the Python console (import myfile), then make changes to the file, and try to import it again. Your changes won't get noticed by the console, and your old version of the file will be used.

Instead, run reload(myfile) to reload the module rather than import it.

### 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".

• Windows: C:\Users\<username>\AppData\Local\Programs\Python\35-32\python.exe or C:\Python35\python.exe
• Mac: /usr/local/bin/python3.5 or /System/Library/Frameworks/Python.framework/Versions/3.5/bin/python. (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.)
• Teaching lab: /usr/local/bin/python3.5