TL;DR Developing for GlowScript requires setting up a rather extensive, but straightforwardly installed, development environment. Actual coding is done in JavaScript.
GlowScript is an online programming environment inteneded to be used to teach computation in introductory physics, although it has other applications and purposes. Although GlowScript users write code in Python (Specifically VPython, which is compatible with Python code written for Jupyter Notebook), GlowScript itself is written and maintained in JavaScript. In this post, I will describe in detail how to set up the necessary development environment on your Mac. I will focus on the Mac because the official instructions here qon’t quite match what is necessary on a Mac.
You will need Web access, a good programming editor (I use BBEdit), and I recommend using Chrome as your browser, at least for GlowScript development purposes.
Step 1. Install Anaconda Python. I have a detailed post on installing Anaconda’s Miniconda distribution and setting it up for VPython. The tools used for GlowScript development specifically require Python 2.7, which is officially deprecated. Read on to learn how to deal with this.
Step 2. In a Terminal, issue the following command:
conda create -n glowscript-dev python=2.7 and press enter.
This will create a new sandboxed environment named glowscript-dev (of course you can use any name you choose) that specifically runs Python 2.7. Other Python versions installed will not be affected.
The command
conda info –envs
should list your currently defined environments, and you of course should see glowscript-dev (or whatever name you chose) listed there.
Step 3. Next, issue the following command:
conda init and press enter
and follow any instructions you may see. After doing this, you should see the currently active Anaconda environment in parentheses to the left of your system prompt in Terminal. This is a VERY handy feature! Next, issue the following command:
conda activate glowscript-dev and press enter
and this should now be your currently active environment. THIS MUST BE DONE BEFORE INSTALLING THE REST OF THE DEVELOPMENT SOFTWARE BECAUSE DOING SO CURRENTLY REQUIRE PYTHON 2.7. NO OTHER VERSION WILL CURRENTLY WORK.
Step 4. Download the GlowScript source files. Go to https://github.com/vpython/glowscript and over on the right, look for the green button labeled Clone or Download. Click it, and then click on Download ZIP. This will download the file glowscript-master.zip into your Downloads folder. Open a new Finder window, and navigate to your Documents folder (~/Documents). Copy the glowscript-master.zip file to your Documents folder, and double click it to unzip it. This should create a new folder named glowscript-master. For simplicity, I recommend renaming this new folder to just glowscript. You can now safely drag the copy of glowscript-master.zip to the Trash, and if you wish you can also now do the same to the copy of that file in your Downloads folder.
Step 5. Download the Google Cloud SDK for Python. Go to https://cloud.google.com/appengine/downloads and look under Standard Environment. Click on Python. Scroll down to Installing Cloud SDK for Python 2. COMPLETELY IGNORE STEP 1 SHOWN THERE! YOU HAVE ALREADY INSTALLED PYTHON 2.7 IN STEP 2 WHEN YOU CREATED YOUR NEW ANACONDA ENVIRONMENT! Look under Step 2, Install and initialize Google Cloud SDK, and click blue button labeled DOWNLOAD AND INSTALL. Scroll down to the table under Step 2 and look for macOS 64-bit (x86_64). Click on the file for that architecture, currently google-cloud-sdk-276.0.0-darwin-x86_64.tar.gz, to download it to your Downloads folder. Copy this tar.gz file to your Documents folder (~/Documents) and double click it. This should create a folder named google-cloud-sdk. In Terminal, navigate to ~/Documents/google-cloud-sdk and MAKE SURE YOUR ANACONDA ENVIRONMENT NAMED glowscript-dev IS CURRENTLY ACTIVE! Run the install script by issuing the command:
./ sudo install.sh and press enter
Enter your admin password, and follow any prompts. Let the script do whatever it needs to do. Next issue the following command:
./sudo gcloud components install app-engine-python and press enter
Enter your admin password and follow any prompts. Let the script do whatever it needs to do.
You can now safely drag the copy of google-cloud-sdk-276.0.0-darwin-x86_64.tar.gz to the Trash, and if you wish you can also now do the same to the copy of that file in your Downloads folder.
Step 6. To fire up the GlowScript environment, get into a Terminal window and MAKE SURE YOUR ANACONDA ENVIRONMENT NAMED glowscript-dev IS CURRENTLY ACTIVE! Navigate to the master glowscript folder by issuing the following command:
cd ~/Documents/glowscript and press enter
Next, simply issue the following command:
dev_appserver.py app.yaml and press enter
Finally, launch Chrome (or other browser of choice, but I recommend Chrome because it gives detailed debug information when running GlowScript programs) and point it to
localhost:8080
You should now see the GlowScript programming environment in the browser and should be able to write and run programs.
Making changes to the GlowScript system itself consists of editing any of numerous JavaScript files in various places. Before attempting any of this, navigate to glowscript/docs and read the file GlowScriptOverview.txt.
You are now all set up to make changes to the entire GlowScript system. You can fix bugs, add features, or anything else you wish. Let me know if you have questions!