Tag: IDE

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>dev_appserver.py
          Here you need to enter the location of the dev_appserver.py file installed in your Google App Engine SDK. On Windows the default installation is C:Program Files (x86)Googlegoogle_appenginedev_appserver.py. 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">
      	<CLASSES>
      	  <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" />
      	</CLASSES>
      	<SOURCES />
        </library>
      </component>
      
    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?

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. By default, it should be included on Mac. I have version 2.7. Perfect!

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 TextWrangler, which you can download here.

After downloading, move the applications that ask to be moved to your Applications folder. Apple sure makes installs easy. Now time to make everything play nice together!

Step 2: Set Up Run/Debugging in PyCharm

I used a lot of information from this website to figure this step out. It was written for Windows though, so I had to change a few things.

The first thing you’ll notice after you open PyCharm is a dialogue box that says “Do you want the application “PyCharm CE.app” to accept incoming network connections?” I believe you have to select yes for it to be able to work properly with Version Control, the updater, or some other programs.

Now to set up run/debugging:

  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 these examples I’ll refer to it as <myproject_path>.
  1. 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>dev_appserver.py
        Here you need to enter the location of the dev_appserver.py file installed in your Google App Engine SDK. On Mac OS X the default installation is /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/dev_appserver.py. 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. Don’t ask, I don’t know why.
        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 OKgae-mac-preferences
  1. Check the python debugger settings:
    1. PyCharm > Preferences…
    2. Expand the tree to Build, Execution, Deployment > Python Debugger
    3. Ensure the option Attach to subprocess automatically while debugging is ticked.

At this point, the basic PyCharm configuration for python GAE debugging is done. To debug, add a breakpoint in the python file and run in debug mode. However, I had a few problems when I tried to run it.

First, I got an error that said lxml was missing.

Lxml is a library of some sort. PyCharm actually has a robust library import system built directly into it. To find it:

    1. PyCharm > Preferences…
    2. Expand the tree to Project:coursebuilder > Project Interpreter
    3. Check to see if lxml is included in the list of libraries.

In my case, it was missing, so I tried to add it to the libraries.

    1. Click the little “+” in the lower-left corner
    2. Type “lxml” in the search bar, and select it
    3. Click Install Packages.

I get a “pip could not be found” error. Great.

Pip is the Python library downloader. Apparently, it’s not included in Python 2.7 by default, so open up a Terminal and put the following command in:

sudo easy_install pip

It will then ask for your password, and install pip for you!

Trying the above method to install lxml, I received another error, and the only way I could figure out to install lxml was to use a workaround, utilizing xcode—the Apple development suite. I don’t know if it will work without xcode explicitly being installed on your machine or not.

sudo CPATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2 CFLAGS=-Qunused-arguments CPPFLAGS=-Qunused-arguments pip install lxml

Now my CourseBuilder website runs correctly! Press the green play button to run the server. To see your website, you click one of the three links will appear in the terminal. By default, it runs on port 8080.

Setting up auto complete, on the other hand, is another project for another day.