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. You’ll be able to complete your work for this course using a personal computer or any machine in one of our teaching labs. If you haven’t used the teaching labs before, here’s a great FAQ for new students to check out.

This guide will take you through the process of installing and configure the necessary software for CSC148 on your personal computer or on the teaching lab machines.

Let us know as soon as possible if you’re having difficulties with your setup, and we’ll help you the best we can! We’ll be keeping track of common issues in the Troubleshooting & Tips section at the end of this guide.

Setting up your personal computer

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.6.0 or later, and will almost certainly run into some trouble if you’re using Python 2 to 3.5. 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 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 its defaults are a little too much to handle when we’re just 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 you to use this semester.

  1. Download the file at this link.
  2. Extract the contents of that file into any folder you like, such as your “Documents” folder.

    On Windows, use a program like Winzip to extract the contents of the file.
  3. Start PyCharm.
  4. When prompted to choose a project, select “Open”. Navigate to your new csc148 folder, select it and press OK.
  5. Select “File -> Import Settings…” on the menu. 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 (Windows)/⌘ + , (OSX) to access the Settings window. Or, look under “File -> Settings” (Windows)/“PyCharm -> Preferences” (OSX) to access this window.
  9. In the Settings window, go to “Project: csc148 -> Project Interpreter”.
  10. Select Python 3.6.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, then jump down to Locating your Python interpreter below.

Part 3: Installing Python libraries

For this course, we will be using a few Python libraries that must be installed separately. The easiest way to install them is to use PyCharm:

  1. Make sure you’ve opened your csc148 project (see Part 1).
  2. In the Project pane on the left side of the screen, open up the Requirements.txt file.
  3. You should receive a message at the top of the opened file about missing packages. Select install requirements.
  4. (Updated) If you don’t see this message appear, install the requirements by opening the Settings window, and doing the following:

    1. Open Project: csc148 -> Project Intepreter.
    2. Ensure that you have Python 3.6 selected in the “Project Intepreter” dropdown.
    3. Press the green “+” icon, and type in the name of one of the packages in Requirements.txt, e.g. python-ta. (Don’t include the ==1.2.0.)
    4. Select the package, and press “Install Package”.
    5. Repeat these steps for all packages listed in Requirements.txt.

Part 4: Working with PyCharm

That’s it! You can play around with PyCharm’s settings: changing the appearance, keyboard shortcuts, etc. We’ve given you a sample file called welcome.py in the csc148—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 annotations so that it gives us relevant suggestions.

Setting up on the Teaching Labs

Note: because the CSC148 software has already been installed on the teaching labs, the steps you’ll perform here are about configuring this software instead. If you are setting up your personal computer, follow the above instructions instead.

Part 1: Configuring PyCharm

PyCharm is a very powerful software development tool that’s used by industry professionals around the world. It’s very powerful, but its defaults are a little too much to handle when we’re just 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 you to use this semester.

  1. Download the file at this link.
  2. Extract the contents of the file into any folder you like, such as your “Documents” folder. 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.
  3. Start PyCharm, which 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 to access the Settings window. Or, look under “File -> Settings” to access this window.
  9. In the Settings window, go to “Project: csc148 -> Project Interpreter”.
  10. Look for Python 3.6.2 in the dropdown menu for the Project Interpreter.

    If you don’t see it in the dropdown (likely the case on the Teaching Labs), then jump down to Locating your Python interpreter below.

Troubleshooting & Tips

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

Locating your Python interpreter

The Python interpreter is the program on your computer that 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 Settings window, go to Project: csc148 -> Project Interpreter.
  2. In the Project Interpreter dropdown menu, click on “Show All”.
  3. Click on the “+” icon on the top-right of the new window, and select “Add Local”.
  4. 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 something like:
    • Windows: C:\Users\<username>\AppData\Local\Programs\Python\36-32\python.exe or C:\Python36\python.exe
    • Mac: /usr/local/bin/python3.6 or /System/Library/Frameworks/Python.framework/Versions/3.6/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 labs: /usr/local/bin/python3.6
  5. After you’ve selected the Python interpreter, click OK and then select it in the other window.
  6. Restart PyCharm.

I have a file hello.py, but when I try to run 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 have a file hello.py, but when I try to run import blah in the Python Console, PyCharm can’t find the module. It’s in a folder that’s marked as Sources Root.

Two possibilities:

  1. If you just marked the folder as Sources Root, you’ll need to restart PyCharm for this change to take effect.
  2. It could be that PyCharm isn’t searching any of the “Sources Root” folders. This is because you haven’t imported the given settings.jar file.

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-10 in the “Configuring PyCharm” instructions you followed above.

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 hello.py into the Python console?

Two ways:

  1. In the console, type from hello 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 testing file.

When I import my file in the Python console, 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

We 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”.

I opened the Requirements.txt file but no message appeared!

We just updated our instructions for an alternate approach—please go back to “Part 3: Installing Python Libraries” to see the update.

I tried to run welcome.py but got an error.

The two most common errors are:

  1. Not using Python 3.6. This will cause the code on line 26 to have an error, as this uses a new feature from Python 3.6.
  2. Not having installed the python_ta library. This will cause the import python_ta statement on line 37 to fail.

Both of these issues can be fixed by reviewing the steps under Setting up your personal computer and making sure you’ve followed them correctly.

(Updated) On some machines, there is another possible error with running the python_ta.check_all line of code. In this case, do the following:

If not: 1. Open the Settings window and go to Project: csc148 -> Project Interpreter. 2. Press the green “+” icon. 3. Search for python-ta in the list of packages. 4. Make sure the “specify version” checkbox is checked, and select version 1.2.1. 5. Press “Install package”.