Setting Up Google CourseBuilder in the PyCharm IDE on Windows

This is a direct follow-up to my last post, Setting Up Google CourseBuilder in the PyCharm IDE on Mac OS X.

There wasn’t a single source of information I could find to get CourseBuilder to work properly, so I decided to put together this guide in the chance that I need to go through the process again. I make no guarantee nor responsibility that it will work for anyone else. All I know is that it worked for me in my particular situation.

Step 1: Download ALL THE PROGRAMS!

CourseBuilder is based off of Python, so check to make sure Python is installed. CourseBuilder doesn’t play nice with version 3, so make sure you have a version of Python 2. I have Python 2.7.10. You can download it here.

PyCharm, my Python IDE of choice (since the others on my project are using it), can be found here.  Grab the Community Version 4.0.6. For some reason, PyCharm 4.5 doesn’t play nice with CourseBuilder.

To run CourseBuilder, you need to have the Google App Engine SDK. The Engine runs as the server of CourseBuilder. If I understand correctly, it would then be impossible to run without it. Download that here. Grab the “for Python” version.

Finally, download Google CourseBuilder here. I was having issues directly clicking “Export to GitHub,” so click on the Downloads page and download the latest zip version. At the time of writing, it was “Course Builder v1.8.0 (6 April 2015).” Check to make sure your copy has a “lib” folder. One time I downloaded it, there must’ve been a problem since it didn’t download the entire program.

Not necessarily required, but I ended up needing a basic text editor for one step. I recommend Notepad++, which you can download here.

After downloading, install the files that ask to be installed. Which should be all of them except CourseBuilder. Now time to make everything play nice together! This was far easier than it was on my Mac.

Step 2: Follow the Directions!

Here, I just followed the directions on this website. In case something happens to it, though, I’ll re-post it here.

Configure python GAE debugging

This is the minimum Run/Debug configuration that will enable you to debug your python for GAE application. It must be set on a per project basis. You’ll need a pre-existing GAE project for this to work. The prerequisites at the end of this post explain how to set up an example GAE application.

    1. Open the GAE project in PyCharm:
      1. Select menu item File > Open…
      2. Select your base project folder (the one which contains an app.yaml file). For our examples we’ll be using the folder C:myproject, which we’ll refer to as <myproject_path>.
    2. Add a new python configuration:
      1. Run > Edit Configurations…
      2. Click the green plus sign “+
      3. In the Add New Configuration list, select Python.
      4. Specify the configuration parameters:
        1. Name: GAE_config
          Choose a name, which we’ll refer to as GAE_config
        2. Script: <GAE_install_path>
          Here you need to enter the location of the file installed in your Google App Engine SDK. On Windows the default installation is C:Program Files (x86) We’ll refer to this location as <GAE_install_path>
        3. Script parameters:
          –automatic_restart=no –max_module_instances=”default:1″ .
          These are the minimum arguments needed for the debugging to work.
          Ensure you include the final argument, “.“: it means the current path, i.e. the working directory in this case.
        4. Working directory: <myproject_path>
        5. Tick the Share box.
          This creates configuration file <myproject_path>.idearunConfigurationsGAE_config.xml, which can be shared with other users and put in version control.
        6. Press OK

PyCharm python run/debug configuration for Google App Engine

  1. Check the python debugger settings:
    1. File > Settings…
    2. Expand the tree to Build, Execution, Deployment > Python Debugger
    3. Ensure the option Attach to subprocess automatically while debugging is ticked.

The basic PyCharm configuration for python GAE debugging is done. To debug, add a breakpoint in the python file and run in debug mode.

Enable code navigation for GAE libraries

To enable PyCharm’s code navigation and completion, we need to add the GAE SDK to PyCharm’s list of External Libraries.

  1. Close PyCharm
  2. Create a GAE SDK library file:
    1. In <myproject_path>.idea, create a directory named libraries.
    2. In <myproject_path>.idealibraries, create an xml file named GAE_SDK.xml
    3. Copy and paste the xml code below in GAE_SDK.xml:
      <component name="libraryTable">
        <library name="GAE_SDK" type="python">
      	  <root url="file://C:/Program Files (x86)/Google/google_appengine" />
      	  <root url="file://C:/Program Files (x86)/Google/google_appengine/lib/django-1.5" />
      	  <root url="file://C:/Program Files (x86)/Google/google_appengine/lib/jinja2-2.6" />
      	  <root url="file://C:/Program Files (x86)/Google/google_appengine/lib/webapp2-2.5.2" />
      	<SOURCES />
    4. Update the paths C:/Program Files (x86)/Google/google_appengine as needed to point to your GAE install location. See the next section if you’d like to use a per user macro path variable instead. To add more GAE libraries, add them to the list (in a similar way to webapp2, django and jinja). Save.
  3. Update the project’s .iml file with the GAE SDK reference:
    1. Open <myproject_path>.ideamyproject.iml
    2. Add the line below to the component element and save.
      	<orderEntry type="library" name="GAE_SDK" level="project" />
  4. Open PyCharm. GAE_SDK should be listed under the External Libraries in the Project viewer (View > Tool Windows > Project). In the python code, you can open class definitions (right-click on class) and code completion works.

After this, I set it up to push directly to my GitHub repository. To do so:

  1. VCS > Import into Version Control > GitHub
  2. Give PyCharm your username and password
  3. Add a master password if you have one, otherwise leave it blank
  4. Select a name for you repository (probably coursebuilder)
  5. Use VCS > Commit Changes to push modifications to your repository.

At this point, I had a “no module named lxml.html” error, the very same as when I tried with my Mac.

To fix this, I used PyCharm’s built-in library manager. And it worked this time!

  1. File > Settings…
  2. Expand Project: coursebuilder > Project Interpreter
  3. Click the green plus sign “+
  4. Typed “lxml” in the search bar and highlighted lxml in the menu
  5. Clicked Install Packages.

The library downloaded, installed, and then the program ran! How’s that for easy?