Optimizing Python environment setup for beginning students

One of my most used (in a past-life, that is) Python modules happens to be a certain PyMySQL, a MySQL client module that is implemented entirely in Python.  Part of the appeal of this particular module is cross-platform capability: by not relying upon any precompiled machine binaries, you can theoretically use this module in a Python programming class without having to worry about who has what operating system, a serious plus if you’re trying to get this module out to 200+ students with a wide variety of platforms.

That is, until you realize that that particular module now has a dependency on setuptools for a find_package function, and now you need to get setuptools working on Windows.  It’s not a terrible pain, just a bit more confusing if you’re not particularly used to using a terminal, which most of the students in question haven’t even heard of, let alone used before.  Add to that the necessity of installing wget or curl on Windows to follow most installation instructions, and you have a recipe for confusion and bad times for both students and teaching staff.

Instead, I endeavored to create a script that will automate the entire process for us, from Python installation to module installation.  Pedagogy aside, we want to keep students out of the terminal or control panel, as this is a Python coding class, not a system administration course, my options were severely limited.

My first course of action was to write a Powershell script that could perform the installation of PyMySQL.  One of the biggest benefits of Powershell over the traditional command prompt is the ability to drop into .NET when necessary to perform things like file downloads.  While this isn’t quite as pretty as using something like wget, it does the job extremely well, and gives me the flexibility I need to perform the installation correctly.

However, upon testing, I realized that the default ExecutionPolicy is Restricted, meaning no script files are permitted to run.  Changing this requires either a registry edit or typing a command into Powershell itself, violating the “Stay away from the terminal” rule.  Therefore, I had to resort to dropping back into the traditional shell, essentially writing a batch script shell around the Powershell script I had previously written, automatically downloading the latest installation powershell script from a web directory and then letting that script perform the rest of the installation.  With that, it’s easy for us to add additional modules or change the version of Python installed during the initial setup without the students ever needing to see anything; all they have to do is download the batch file and double click it!  I’d say that’s simple enough!

To see/use the scripts, visit my Skydrive scripts folder.  There are two flavors: install-pymysql.(bat|ps1) and setup-python-environment.(bat|ps1).  The install-pymysql.bat version assumes that you have Python 3.3 already installed and in the default directory, C:\Python33.  I avoided using the Path because it is very possible that students have an older version of Python installed to the path for use in another class which would preempt Python 3.3.  The setup-python-environment.bat variant performs a completely clean install of Python 3.3 as well as PyMySQL.  Just download and run the appropriate batch file and it’ll do the rest.

Fortunately, this is fairly easy to alter to install your own set of modules; just add additional calls to easy_install.exe with the modules of your choice!  I may want to do a little bit of refactoring in the future to relaunch Powershell in an admin context rather than launching all the installers in their own individual admin context, which will result in less UAC popups.

If you want to host these scripts yourself, make sure to upload the ps1 file to your web host and alter the batch file accordingly so that it downloads the right ps1 file!


2 thoughts on “Optimizing Python environment setup for beginning students

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s