So You've Decided to Use Python - What's Next?

posted September 18, 2019 and revised June 16, 2020
by Todd Zimmerman

So you’ve decided Python is the language for you.  Maybe it was love at first sight, or maybe several of your colleagues are using it so you thought you’d give it a go.  There are still several choices you need to make before you can plunk some code down in front of your students and the number of choices can be dizzying.  This article will run through some of the options and give you some advice on how to pick the best choice for your students.

 

TLDR: Use Trinket.io online for introductory courses and run Jupyter Lab locally for upper level courses.

 

1) Python 2 vs. Python 3

Back in 2008, Guido van Rossum (the Benevolent Dictator for Life) and friends released Python 3.0.  This was an updated version of Python that broke backward compatibility with key elements of Python 2.  Although the elements that are broken may not seem like a big deal, anyone who has tried to move a perfectly working Python 2 program over to Python 3 realizes this is no trivial problem.

 

In the past it made a lot of sense to stick with Python 2 because VPython wasn’t available for Python 3.  There were also several other add-ons only available in Python 2, but these didn’t tend to be important to teaching physics.  These days VPython is only running under Python 3.  There isn’t any compelling reason to stick with Python 2 any more.

 

The end-of-life date for Python 2 is 2020, which is almost upon us.  There will be no more updates so there is no reason to stick with Python 2 going forward.  If you haven’t learned Python yet, start with the latest version of Python 3.  If you are an old hand at Python 2, time to make the switch.

 

2) Installed vs. In-the-cloud

The next question that confronts you is whether to try to run Python locally on your own machine or run it in the cloud.  Both have pros and cons.

 

Installing Python on your computer has the benefit of speed and control over the add-ons that you can use.  You have access to your entire processor, memory, and disk drive so those are the only constraints.  It can be useful to be able to install the add-ons that you want to use.  The main downsides are that you have to install everything, which can be a headache.  Even programming-savvy students can have issues getting all of the pieces needed to run Python playing well together.  A second downside to running Python locally is that delivering and collecting assignments from students provides an extra step to your workflow which can impede a smoothly running class.  I don’t recommend this option for introductory courses, especially with a large number of students in them. For more advanced courses this might be a better choice because you can use Jupyter notebooks and install the add-on modules that are useful for a particular class.

 

There are a number of places you can run Python in the cloud (I’ll discuss them each below).  There is no installation required, just a browser connected to the internet.  The primary limitations of running in the cloud are (1) you can’t customize which add-ons are available, (2) you have limited resources in terms of computing power, memory, or storage space for some of them, and (3) distributing and collecting material from students can still be a bit of a hassle.  This is the best option for introductory courses.

 

2.1) Running Python Locally

Once you’ve decided to run Python on your computer, you now need to decide how to install Python.  The easiest answer is to use Anaconda, which is a distribution, a collection of software that makes installing and using Python easier.  Go to Anaconda Python/R Distribution - Anaconda and download the Python 3 version.  Most computers will use the 64-bit version.  In addition to the core Python software and library, it includes conda, which is a package management system that makes installing additional libraries easy.  _Link to article on getting started with Anaconda?.

 

There are other distributions, such as the Enthough’s Canopy Python Distribution or ActivePython, or you can install vanilla Python from Python.org, but unless you have a compelling reason for doing so I’d recommend sticking with Anaconda.

 

2.1.1) Jupyter Notebooks vs. Jupyter Lab vs. Text Editor/IDE

There are a number of text editors or more extensive Integrated Development Environments (IDE) for Python, but for class-work I find that using Jupyter Notebooks are a better way to go.  In particular using Jupyter Lab is a good option these days.   

 

 

2.2) Running Python in the Cloud

There are a number of different options for running Python in the cloud, such as Glowscript.org, Trinket, Microsoft Azure, Google Colaboratory, or CoCalc, to name a few.  All have free options. 

2.2.1) CoCalc - Collaborative Calculation in the Cloud

CoCalc, which stands for Collaborative Calculations, allows you to run Python in a Jupyter notebook.  It has quite a few extra features, such as the ability to distribute, collect, and grade assignments.  It also has a very robust tool for collaborating in real time with students in a notebook, as well as chatting with them in the notebook.  This is an amazingly useful feature and I’d love to see regular Jupyter notebooks implement this somehow.  The main drawback to CoCalc is that the free version shares CPU time with other users, so it can be very slow, especially when running VPython.  There is an option to pay for access to more processor power.  Paying for an individual account upgrade is reasonable but purchasing for an entire class can start to run into the thousands of dollars fairly quickly.  If real-time collaboration or the enhanced assignment management are important to you than this is a good place to look.

 

2.2.2) Glowscript.org

Glowscript VPython allows VPython scripts to be run in your browser.  Glowscript.org is a website created solely for the purpose of running VPython scripts without having to install anything on your computer.  Unlike CoCalc, Azure, or other cloud sites, the programs are run on your computers so scripts tend to run very quickly. You can run scripts on the website without an account but to be able to edit and save code you will need a free account. Bruce Sherwood has some example code here.  The website is fairly bare-bones so you’d need to use your own LMS for distributing and collecting assignments.

 

In terms of speed, Glowscript VPython actually runs faster than running VPython 7 for many things.  This is because Glowscript VPython uses JavaScript, which is compiled, vs. VPython 7, which is an interpreted language.  Compiled languages are usually much faster than interpreted languages.

 

2.2.3) Trinket.io

Trinket is a website that allows you to run Glowscript VPython without installing anything locally.  It provides more features than Glowscript.org.  The main benefit is the ability to create courses that contain a series of webpages with embedded code blocks (called Trinkets).  Students are able to modify and run the code in their browsers.  To collect assignments and provide you will still need to use another  resource like your LMS using the free plan.  However, you can upgrade to Trinket Connect for less than $100 a year($72 at the current time), which allows you to collect assignments and provide feedback on the site.  The nice thing is that only the instructor needs to pay the fee to have access to this option.  You can see the list of benefits of signing up for Trinket Connect here.  I find it is well-worth it.  For an introductory course I strongly recommend this option. 

 

2.2.4) Google Collaboratory

Unfortunately it looks like VPython doesn’t run under Colab, so I haven’t made use of this.  It might be worth looking at for upper level courses but I haven’t put in the time yet to say much about this.

 

3) My Decision

I’ve settled on Trinket for my introductory course.  I like that I can create pages within Trinket that have the coding boxes embedded in them.  I’ve paid for Trinket Connect, which allows me to create assignments that I can collect, grade, and give feedback on.  They don’t charge a per-student fee, which I also like - I just have to pay for the Connect account myself.

 

In upper level courses I use Jupyter Hub run on a local server, although I frequently recommend students install Python locally and upload the results to the Hub when done.  This has worked fairly well but it’s not as seamless as I’d like.