jupyterhub and vpython

435 views
Skip to first unread message

Dirk van Deun

unread,
Sep 27, 2019, 5:28:14 AM9/27/19
to VPython-users
Has anyone had any success using vpython with jupyterhub ?  The basic problem is running vpython on another computer than the browser it is accessed from; but now as part of the smooth user experience that jupyterhub wants to offer.  It seems to me that this will require some tweaks to the code, plus some firewall magic on the server.  Any experiences to share ?

Matt Craig

unread,
Sep 28, 2019, 10:59:11 AM9/28/19
to VPython-users
Hi,

This has been on the to-do list few several months now...we can't run vpython >=7.5 on binder because it blocks the websocket server that we set up.

I think the solution is to use https://jupyter-server-proxy.readthedocs.io/en/latest/ but haven't had time to try it.

Matt Craig

Dirk van Deun

unread,
Sep 30, 2019, 4:55:37 AM9/30/19
to VPython-users
On Saturday, September 28, 2019 at 4:59:11 PM UTC+2, Matt Craig wrote:
Hi,

This has been on the to-do list few several months now...we can't run vpython >=7.5 on binder because it blocks the websocket server that we set up.

I think the solution is to use https://jupyter-server-proxy.readthedocs.io/en/latest/ but haven't had time to try it.

Matt Craig


Hi,

I can see that jupyter server proxy might be usable as a component of a solution, but it seems to me that vpython would have to be aware of the fact that it is being proxied for this to work (at the very least to pass the new urls to the browser).  So am I understanding correctly that it cannot be done with vanilla vpython, and that jupyter server proxy is a component I can use as a starting point if I want to hack my own vpython-for-jupyterhub ?

Dirk

John

unread,
Oct 1, 2019, 2:13:37 PM10/1/19
to VPython-users
In order to get vpython to work from a remote host we need to figure out how to connect a websocket to the remote host. Currently vpython only runs on a local host since we are only connecting the websocket to a port on the local host with the javascript code.

ws = new WebSocket("ws://localhost:" + port + uri);

Here is a sample notebook to create a websocket connection. In the first cell is some python code to create a websocket server on an available port that runs in the python kernel. In the second cell print out the port number that was used by the websocket server.  In the third cell is some javascript code to connect the websocket to the server. You will need to set the variable

var port = 51929

in the javascript code to the value output from the second cell and then execute the code. 

If you do this when you run the notebook locally on your computer then you will see a message in the javascript console that the websocket is connected.

The problem I have is that I don't know how to set up the websocket connection when the websocket server from the first cell  is running on a remote computer. If you know how to connect the websocket to a remote computer so that this notebook will run correctly the let us know it can be done so that we can try it out.

John

John

unread,
Oct 1, 2019, 2:26:35 PM10/1/19
to VPython-users
Here is the notebook I was referring to with the websocket code to try out.

John

unread,
Oct 3, 2019, 8:27:21 AM10/3/19
to VPython-users
I did some searching on the internet on how to connect a websocket from javascript to python kernel running on binder and came across this example which I was able to reproduce and check that it worked.


From the three first comments in the post I reproduced their result here on binder.


To see this simple chat example working on binder you click on the above link and then when binder is up and running you do

    New -> Terminal 

and type into the terminal

    python server.py

to launch the server. Then you copy the webpage address on binder 


and create a  new browser tab and replace the "/tree" part of the address with "/proxy/8000"


Then you get a webpage with a working simple chat example which has a working websocket. From the post they connect the websocket using these two lines of code.

+    var url = 'wss://' + document.location.hostname + document.location.pathname + '/chat';
+    websocket = new WebSocket(url);


This example is from a server running outside the notebook on binder. I haven't figured out yet how to connect a websocket to a server launched from inside a notebook like we do in vpython.

On the binder forum someone mentioned that Bokeh also used websockets in their project.


and had this repo for running Bokeh on binder.


John

John

unread,
Oct 3, 2019, 9:23:33 AM10/3/19
to VPython-users
After some further experimentation I got the websocket to open with the following code in my example program.

        ws = new WebSocket(url);

And the javascript console showed the following

***WebSocket Connection Opened***         VM80:26 
***WebSocket Connection Closed***

So the websocket connection was opened to binder and then closed after about a minute of inactivity.

So it looks like we need to construct a websocket address similar to the one above in vpython in order to get vpython to work on binder. 

I constructed the address in javascript with

var url = 'wss://' + document.location.hostname + document.location.pathname + '/ws';

and then replaced 'notebooks' with 'proxy/port' in the url address that was returned by above line of code.


John

On Tuesday, October 1, 2019 at 11:26:35 AM UTC-7, John wrote:

John

unread,
Oct 3, 2019, 10:26:13 AM10/3/19
to VPython-users
Here is a working version of websockets from my demo program on binder 


To see it working click on this link and open the notebook WebsocketTest.ipynb . Then execute the first two cells. The second cell prints out the port number. Then place this port number in the line

var port = 42527

in the third cell and then execute the third cell. Then open up the javascript console and you will see a message that the websocket is connected and that we are periodically sending "Hellow World" to the websocket.

***WebSocket Connection Opened***                 98VM75:36 
Sent 'Hello World' to websocket

So this demo program illustrates how to get websockets working on binder in a similar way to how websockets should work in VPython.

In order for this to work I needed to set up a requirements.txt file in the binder folder which contained the following entry.

jupyter-server-proxy


John

Dirk van Deun

unread,
Oct 3, 2019, 11:11:07 AM10/3/19
to VPython-users
Hi John,

I appreciate the effort you have put into your replies, but I am afraid I have neglected to sketch the context of my original question.  The context is that a colleague of mine teaches an elementary programming course to science students who have no special interest in computer science, so he does not want to dwell on how everything works behind the scenes but wants to get to drawing graphs with vpython as quickly as possible.  If he tells the students to use jupyter, there will be a lot of hassle about how to install this on everybody's laptop under different operating systems; so he would prefer to use jupyterhub and just tell his students to open a browser and log in with their university account and start doing stuff.  That works fine for doing some calculations, but as soon as you try to draw anything with vpython, the illusion breaks down and you notice that jupyterhub is not jupyter.  What I wanted to know was whether it was possible to avoid the illusion breaking down; unfortunately saving the time needed to install jupyter is not real progress if afterwards we have to tell the students about urls and proxies and ports before they can draw their first sphere.

Best,

Dirk

John

unread,
Oct 3, 2019, 12:34:43 PM10/3/19
to VPython-users
Hi Dirk

   If you go to the following website you will see many sample vpython notebooks that you can run on a remote computer using the mybinder.org  service.


If you click on this link then you will see that binder is launched. Binder is a free service that uses something called binderhub which is similar to Jupyterhub. After you click on this link and once the launch is complete after about a minute you will be presented with the jupyter notebook interface. To see examples of vpython demo programs that you can run in a jupyter notebook on this binder service go to the Demos directory and open and execute any of the notebooks in this directory. If you do so then you will see vpython programs running correctly from a remote computer somewhere on the internet. I think binder uses the google cloud platform so these demo notebooks are running vpython code somewhere on the google cloud platform.

From this jupyter notebook interface on binder you can also create your own vpython notebook with your own vpython program and execute it.

This link to vpython running on mybinder.org uses an older version of VPython but it demonstrates that vpython can indeed work when running from a remote computer. However this is an older version of vpython prior to vpython 7.5.0  and also uses an older version of Jupyter notebook and ipython kernel. With the latest version of the Jupyter Notebook we had to start using websockets in order to get vpython to work properly in a jupyter notebook. However our original websocket solution only worked on a local machine and not on a remote service such as binder or jupyterhub. However once we have a fix for connecting websockets to a remote computer then the latest version of vpython should work on a remote service such as binder or jupyterhub.

John 

Wayne

unread,
Oct 3, 2019, 1:03:02 PM10/3/19
to VPython-users
Thanks for posting that, John. I was drafting a post to say much the same thing.
However, I was going to use the RStudio binder launch from  https://github.com/binder-examples/r  as an example because I didn't realize my fork of the older VPython version still worked. 
Pleasantly surprised to see my fork still works. I had tried launching it from the repo the other day because I wanted to suggest to Dirk that possibly his colleague could use it in a pinch if they needed this all working yesterday. (Keep in mind this was before you made the great progress you have now.) And it hand't worked; I wonder if I had too much going on in my browser at the time?

The repository with the launch button is at https://github.com/fomightez/vpython-jupyter if you anyone needs an easier way to launch.

John

unread,
Oct 3, 2019, 1:06:30 PM10/3/19
to VPython-users
Hi Matt

   I think I have a solution that might work to get vpython working on binder again. We will need to add the line

jupyter-server-proxy

to the file requirements.txt in the jupyter vpython repository. We will also need to modify the file glowcomm.js . If we replace the line number 26 in glowcomm.js containing

ws = new WebSocket("ws://localhost:" + port + uri);
with the  following code

        var loc = window.location, new_uri, url;
        if (loc.protocol === "https:") {
            new_uri = "wss:";
        } else {
            new_uri = "ws:";
        }
        if (document.location.hostname.includes("mybinder")){
            new_uri += '//' + document.location.hostname + document.location.pathname + uri;
            url = new_uri.replace("notebooks", "proxy/"+port);
        }
        else {
            new_uri += '//' + document.location.hostname + ':' + port + uri;
            url = new_uri;
        }
        ws = new WebSocket(url);

then we should be able to establish the websocket connection to vpython running on binder and get vpython up and running again on binder.

We will also need to test websocket connections to notebooks running on JupyterHub on a remote computer but I don't have a such a setup to try it out.

John

Wayne

unread,
Oct 3, 2019, 1:15:48 PM10/3/19
to VPython-users
Hi John,
I could make a fresh JupyterHub (an instance of The Littlest JupyterHub) and provide you with access if that would help you in testing?

Wayne

John

unread,
Oct 3, 2019, 1:23:51 PM10/3/19
to VPython-users
Hi Wayne

   Yes that would be great. Can you provide instructions on how to access your JupyterHub instance on this forum. If not I can give you my email address.

Thanks

John

Bruce Sherwood

unread,
Oct 3, 2019, 4:06:20 PM10/3/19
to VPython-users
"If he tells the students to use jupyter, there will be a lot of hassle about how to install this on everybody's laptop under different operating systems; so he would prefer to use jupyterhub and just tell his students to open a browser and log in with their university account and start doing stuff."

This is a situation where glowscript.org or trinket.io is the appropriate environment. These students almost certainly don't need access to the world of Python modules, so the inability to access such modules is not a problem. A student can simply log in to one of these web sites and program, using VPython.

Installation is a bear.. Here are two relevant anecdotes: Starting in 1997 the "Matter & Interactions" (M&I) calculus-based intro physics curriculum created by Ruth Chabay and me has included a serious introduction to computational modeling, because it is central to all of STEM. For many years students installed Python, installed the VPython module, and, on a Mac, installed an update to Tcl. When it became possible to write VPython programs at glowscript.org (previously programs had to be written in JavaScript), something very interesting happened. Georgia Tech was the first M&I-using institution to switch from installed Python to Glowscript, and they reported greatly increased enthusiasm for and acceptance of VPython. We had not realized what a daunting barrier it was to students to deal with software installations, which can fail for any number of arcane reasons. The install barrier sent a strong signal: "This is a very techie course and you're going to fail." And it wasn't just install issues. Students also had to know about folder and files and file extensions, all of which was opaque to many STEM college freshmen.

Anecdote #2: Our friend Ed Angel is the author of the most widely used upper-level computer science textbook on 3D computer graphics. His early editions were based on C++ and OpenGL, and at the start of every semester he got a flood of anguished emails from all over the world begging for help in getting C++ compilation and OpenGL installed and working on diverse platforms. His recent editions are based on JavaScript and browser-based WebGL, and all those anguished pleas for help are gone. If upper-level computer science students can't deal with installations, it's not surprising that intro physics students would have trouble. Among the many advantages of a browser-based approach is that platform issues nearly vanish.

Bruce

Dirk van Deun

unread,
Oct 8, 2019, 6:50:59 AM10/8/19
to VPython-users
On Thursday, October 3, 2019 at 10:06:20 PM UTC+2, Bruce Sherwood wrote:
"If he tells the students to use jupyter, there will be a lot of hassle about how to install this on everybody's laptop under different operating systems; so he would prefer to use jupyterhub and just tell his students to open a browser and log in with their university account and start doing stuff."

This is a situation where glowscript.org or trinket.io is the appropriate environment. These students almost certainly don't need access to the world of Python modules, so the inability to access such modules is not a problem. A student can simply log in to one of these web sites and program, using VPython.

Yes, but we were actually trying to host something along these lines ourselves.  That would be extra work for us but bring advantages, like flexibility, certainty that the service would not be discontinued in the middle of a semester, and allowing students to turn in assignments easily (just save as "assignment 1").

Dirk

Bruce Sherwood

unread,
Oct 8, 2019, 10:42:40 AM10/8/19
to VPython-users
I see; that makes sense.

There is another modality I should mention. I've been told that for $10 per month (or $6 per month if prepaid) an instructor can purchase the ability at trinket.io not only to see and run a student's program but also to be able to leave comments in the student's code, which sounds like something that would be very useful.

Bruce

John

unread,
Oct 12, 2019, 11:35:06 AM10/12/19
to VPython-users
I fixed the problem of running vpython on JupyterHub. When the next general release of vpython comes out then it should work on JupyterHub. Here is a link to the demo vpython programs running on Binder so you can see for yourself that it works.


I tested it on a JupyterHub that I logged into and it works just like does on Binder.

So you will need to wait until the next release of vpython which should be version 7.5.2 . After you install that version on JupyterHub the students should be able to log into their university account and run vpython programs in a jupyter notebook.

One thing to consider when using vpython on JupyterHub is to enable websocket compression which is a configurable attribute in the jupyter_notebook_config.py file. See the attribute websocket_compression_options in


To enable websocket compression it should be set to 

c.NotebookApp.websocket_compression_options = {}

in the jupyter_notebooi_config.py file in your JupyterHub installation. But this will turn on websocket compression for all notebooks running on the JupyterHub not just for vpython.

John

Bruce Sherwood

unread,
Oct 12, 2019, 10:57:41 PM10/12/19
to VPython-users
Great work, John!

Bruce

Dirk van Deun

unread,
Oct 15, 2019, 8:06:18 AM10/15/19
to VPython-users

So you will need to wait until the next release of vpython which should be version 7.5.2 . After you install that version on JupyterHub the students should be able to log into their university account and run vpython programs in a jupyter notebook.

One thing to consider when using vpython on JupyterHub is to enable websocket compression which is a configurable attribute in the jupyter_notebook_config.py file. See the attribute websocket_compression_options in


To enable websocket compression it should be set to 

c.NotebookApp.websocket_compression_options = {}

in the jupyter_notebooi_config.py file in your JupyterHub installation. But this will turn on websocket compression for all notebooks running on the JupyterHub not just for vpython.


Hi,

That is splendid.  I have made notes of your remarks; we will try it out when there is a new release; and if all goes well, use vpython this way for the course in question starting with the next batch of students (next year).

Thanks,

Dirk

nibheis

unread,
Apr 21, 2020, 5:50:42 AM4/21/20
to VPython-users
Dear John and all,

I've been trying to run vpython on our local jupyterhub (+ jupyterlab 1.2.7).
I have tested version 7.6.1 (latest at the moment) and also 7.5.2b3 without success.

When running:

from vpython import *
sphere()

... all I get is messages ("element is not defined - please check console") and then a blank space that appears.

With 7.5.2b3, I also ran into problems when vpython tries to copy vpython_data to jupyterlab's "static" folder : users don't have right access to this folder.
I copied the files over as root, modifies "with_notebook.py" to skip that step, but that does not help (errors and no blank space)
I went back to 7.6.1 - still not working,

There I am, trying to debug and trace to see what is not working - which is not obvious.

Here is the logs I gathered - when running the cell:

here is the syslog from the server:

systemd-resolved[709]: Server returned error NXDOMAIN, mitigating potential DNS violation DVE-2018-0001, retrying transaction with reduced feature level UDP.
systemd-resolved[709]: Server returned error NXDOMAIN, mitigating potential DNS violation DVE-2018-0001, retrying transaction with reduced feature level UDP.

(twice each time I run the cell)

... and here is the jupyterlab log from the server, for this user (DEBUG):

[D 2020-04-21 09:26:32.410 SingleUserLabApp kernelmanager:417] activity on 92236fbd-65c7-4c14-b42e-447cf6853ea0: status (starting)
[D 2020-04-21 09:26:32.421 SingleUserLabApp kernelmanager:417] activity on 92236fbd-65c7-4c14-b42e-447cf6853ea0: status (busy)
[D 2020-04-21 09:26:32.426 SingleUserLabApp kernelmanager:419] activity on 92236fbd-65c7-4c14-b42e-447cf6853ea0: execute_input
[D 2020-04-21 09:26:32.529 SingleUserLabApp kernelmanager:419] activity on 92236fbd-65c7-4c14-b42e-447cf6853ea0: display_data
[D 2020-04-21 09:26:32.534 SingleUserLabApp kernelmanager:419] activity on 92236fbd-65c7-4c14-b42e-447cf6853ea0: display_data
[D 2020-04-21 09:26:32.696 SingleUserLabApp kernelmanager:419] activity on 92236fbd-65c7-4c14-b42e-447cf6853ea0: display_data
[D 2020-04-21 09:26:32.704 SingleUserLabApp kernelmanager:419] activity on 92236fbd-65c7-4c14-b42e-447cf6853ea0: display_data
[D 2020-04-21 09:26:32.709 SingleUserLabApp kernelmanager:419] activity on 92236fbd-65c7-4c14-b42e-447cf6853ea0: display_data
[D 2020-04-21 09:26:32.713 SingleUserLabApp kernelmanager:419] activity on 92236fbd-65c7-4c14-b42e-447cf6853ea0: display_data
[D 2020-04-21 09:26:32.716 SingleUserLabApp kernelmanager:419] activity on 92236fbd-65c7-4c14-b42e-447cf6853ea0: display_data
[D 2020-04-21 09:26:32.720 SingleUserLabApp kernelmanager:419] activity on 92236fbd-65c7-4c14-b42e-447cf6853ea0: display_data
[D 2020-04-21 09:26:34.724 SingleUserLabApp kernelmanager:419] activity on 92236fbd-65c7-4c14-b42e-447cf6853ea0: comm_open
[D 2020-04-21 09:26:34.863 SingleUserLabApp auth:871] Allowing whitelisted Hub user xxxxxxx
[I 2020-04-21 09:26:34.867 SingleUserLabApp handlers:283] Trying to establish websocket connection to ws://localhost:52525/ws  
[I 2020-04-21 09:26:34.910 SingleUserLabApp handlers:290] Websocket connection established to ws://localhost:52525/ws
[D 2020-04-21 09:26:34.926 SingleUserLabApp kernelmanager:419] activity on 92236fbd-65c7-4c14-b42e-447cf6853ea0: comm_msg
[D 2020-04-21 09:26:34.934 SingleUserLabApp kernelmanager:417] activity on 92236fbd-65c7-4c14-b42e-447cf6853ea0: status (idle)
[D 2020-04-21 09:26:34.941 SingleUserLabApp kernelmanager:417] activity on 92236fbd-65c7-4c14-b42e-447cf6853ea0: status (busy)
[D 2020-04-21 09:26:34.944 SingleUserLabApp kernelmanager:417] activity on 92236fbd-65c7-4c14-b42e-447cf6853ea0: status (idle)
[D 2020-04-21 09:26:34.947 SingleUserLabApp kernelmanager:322] Kernel info reply received: 92236fbd-65c7-4c14-b42e-447cf6853ea0  
[D 2020-04-21 09:26:35.037 SingleUserLabApp kernelmanager:419] activity on 92236fbd-65c7-4c14-b42e-447cf6853ea0: comm_ms

So, it looks like some local websocket is opened... but I am not sure it works as expected.

My questions are: should vpython work on a jupyterhub ? Where can I look further to trace the problem ?

Thank you for you help!
Best regard

Bruce Sherwood

unread,
Apr 21, 2020, 10:29:18 AM4/21/20
to VPython-users
I have no relevant knowledge to be able to help with JupyterHub, but at the risk of saying something that everyone knows, I'll comment on the statement, "The context is that a colleague of mine teaches an elementary programming course to science students who have no special interest in computer science, so he does not want to dwell on how everything works behind the scenes but wants to get to drawing graphs with vpython as quickly as possible."

For this use with this population, it would seem to make more sense for the students to use GlowScript VPython rather than Jupyter or JupyterHub.

Bruce

nibheis

unread,
Apr 21, 2020, 11:41:08 AM4/21/20
to VPython-users
Thank you Bruce for your reply,

Our logic behind offering a locally hosted JupyterHub solution is mainly to provide a fully working platform (like in the statement you commented) and also to protect the privacy of our thousands of students/profs/researchers. We selected this solution (jupyterhub/jupyterlab) because it allows our users to access the full Python (and R, Julia, Scala, Java, SQL, ...) ecosystem, including VPython, without having to log on remote online services ; we keep our users' data under control. That is at least what we're trying to do - and it works very well most of the time.

Unfortunately, I am struggling to get VPython to work with our JupyterHub :-)
I am just looking for some information that would confirm that it is supposed to work and that I need to continue my investigations - or stop them.
Should I understand from your comment that VPython does not work with JupyterHub?

Best regards,
nibheis

John

unread,
Apr 21, 2020, 12:22:03 PM4/21/20
to VPython-users
Hi nibheis

    Yes vpython should work on JupyterHub. I did test that vpython 7.6.1 worked in a classic notebook on JupyterHub when it was released. Someone volunteered to setup a JupyterHub for me that I could use to test vpython 7.6.1 and I tested that all the vpython demo programs worked OK on JupyterHub in a classic notebook. I don't recall testing vpython with jupyterlab on a JupyterHub though.

    However vpython 7.6.1 with jupyterlab 1.2.7 works on mybinder website. Mybinder uses a BinderHub  which is similar to a JupyterHub. You can see for yourself that this combination of vpython 7.6.1 with juptyerlab 1.2.7 works for all the vpython demo programs on mybinder by going to this site.


    If you do this, it will take several minutes for binder to launch but once it completes launching then you can get the jupyterlab interface by changing the word "tree" to "lab" in the address bar. For instance change the address from something like


to 


then go to the Demos directory and run any of the vpython programs in the directory to satisfy yourself that vpython with jupyterlab works on mybinder at least.

I will note that you can't flip back and forth between classic notebook and jupyterlab notebook by changing the word "tree" to "lab" and back again. You will have use either jupyterlab notebook or classic notebook when you launch mybinder using the address


You can however launch mybinder two times in two separate browser tabs and have one running jupyterlab notebooks and the other one running classic notebooks. In this case vpthon works in both.

Things you can check on when you run vpython in jupyterlab on your jupyterhub are to look at the messages in the javascript console. See if there are any error messages in the javascript console.

Also verify that you installed the vpython labextension for jupyterlab with the command.

   jupyter labextension list

The vpython labextension is installed with the command

   jupyter labextension install vpython

John

John

unread,
Apr 21, 2020, 1:01:52 PM4/21/20
to VPython-users
Also verify the vpython version number in your python program.

from vpython import *
print(version)

verify that this prints out vpython version 7.6.1

It is possible to get an error like

NameError: name 'sphere' is not defined

if you have a file named vpython.py in your current directory or path that isn't the vpython.py file from the vpython package.

John

Bruce Sherwood

unread,
Apr 21, 2020, 1:23:57 PM4/21/20
to VPython-users
I do expect that with John's advice and help it should be possible to get things working.

However, it would be useful to me to understand your privacy concerns, if that is what holds you back from using GlowScript VPython with novices. (I hasten to say that one does want students eventually to learn to use professional tools, but in a course where students are being introduced to Python for the first time, access to all Python modules may be irrelevant.)

At glowscript.org it is true that one needs to use a Google login, but I've not (so far) heard any objections to that requirement. Upon first use a student is offered two empty folders, one public and the other private.

If the need for a Google login is the sticking point, note that one can download a zip file, unzip, and run locally, though I'll admit that people have made little use of this capability so the environment is less well developed than that at glowscript.org. One interesting usage case is a school in China where access to glowscript.org is banned but the instructor gives students the zip file. Below is the info from vpython.org. I would be interested to know what are your privacy issues.

At glowscript.org, your programs are stored in the cloud and are accessible from anywhere. However, there are times when you might need to write and run programs even when disconnected from the internet.

Go to this download site and click Download.

Unzip the GlowScriptOffline package to any convenient place on your computer.

Inside the GlowScriptOffline folder, read the README file to learn how to use the package.

nibheis

unread,
Apr 21, 2020, 2:05:46 PM4/21/20
to VPython-users
Thank you very much!
I confirm that it works perfectly on mybinder (with JupyterLab 1.2.7).
I am trying to find where my software stack differs from myBinder:
JupyterLab: 1.2.7
VPython: 7.6.1, 'jupyter' (vs 7.6.1.beta9+38.g3c722b9.dirty, 'jupyter' on mybinder)
Python: 3.6 (3.7 on mybinder)
vpython lab extension: 1.0.0 (enabled OK)

I think my versions are OK - I even compared the two "pip list" outputs.

I was getting 404 error during font loading in the JS console - which I resolved by deploying the "vpython_data" folder to the static folfer in jupyterlab.

I am still getting the "element is not defined - please check console" messages in the output cell, and in the log console.
In the JS console, I get:

***WebSocket Connection Opened*** (just like on mybinder)
but then:
glowcomm onmessage error :  this.wrapper.resizable is not a function (from glowcommlab.js, line 154)


I'll try rebuilding lab again, to make sure all versions are correct and I'll investigate more tomorrow.

Thanks again for your help.

John

unread,
Apr 21, 2020, 3:13:08 PM4/21/20
to VPython-users
Are you building your own vpython labextension or using the one on npm. You mentioned that "I was getting 404 error during font loading in the JS console - which I resolved by deploying the "vpython_data" folder to the static folfer in jupyterlab." which indicates to me that you might have built your own vpython labextension. If so why don't you try using the one on npm which is installed with the command

   jupyter labextension install vpython

unless you have your own vpython labextension in called vpython in your working directory on your machine. 

Also the error you reported

glowcomm onmessage error :  this.wrapper.resizable is not a function (from glowcommlab.js, line 154)

In the github repository line 154 of glowcommlab.js is a blank line


So it looks like you may have changed glowcommlab.js


John

nibheis

unread,
Apr 21, 2020, 4:48:52 PM4/21/20
to VPython-users
Hi again John!

I did use the npm version ; the only difference is that I usually do it in 2 steps:

jupyter labextension install --no-build vpython
jupyter lab build

This is because the deployment of the platform is scripted and the script build once JupyterLab, when all extensions have been installed.

And regarding "glowcommlab.js", I am most certainly sure that I did not modify it. I just check from myBinder, and I have the same line #154:
        console.log("glowcomm onmessage error : ", err.message);

Since "vpython_data" should be deployed while installing the vpython lab extension, I'm starting over and installing it again - maybe I did something wrong previously.
Done - I confirm that "vpython_data" has been placed in "static" correctly.
Latest tests are giving me exaclty the same behaviour: "element is not defined - please check console" x 7 and a blank section appears in the output cell.

Thanks again for your help, I'll try again tomorrow.
nibheis

nibheis

unread,
Apr 21, 2020, 5:00:55 PM4/21/20
to VPython-users
Hi Bruce,

Our privacy concerns are simple, as a public institution we just cannot not force or even encourage our students, researchers and staff to use services that are located overseas and collect their private data AND to store their studies, research material and personal data on servers that we can not control. These are pretty common concerns in all European universities.

Best regards,
nibheis

Bruce Sherwood

unread,
Apr 21, 2020, 5:09:46 PM4/21/20
to VPython-users
Ah. Understood.

I'm not knowledgeable in these issues. Would it make a difference if there were a copy of glowscript.org hosted in Europe? It's possible that this wouldn't address the problem, because GlowScript started in 2011 and remains a "Google App Engine" application, though as I said, it can even run off-line, which solved the problem of usage in China.

Bruce

John

unread,
Apr 22, 2020, 5:54:11 PM4/22/20
to VPython-users
Hi nibheis

    I verified that vpython 7.6.1 works with jupyterlab 1.2.7 on a JupyterHub. I had someone create a JupyterHub for me today with these versions of vpython and jupyterlab and I was able to run the vpython demo programs on the JupyterHub.

One thing that I did need to do after installing the vpython labextension was to login to JupyterHub and then from the from Control Panel in JupyterHub selected  "Stop MyServer" then "Start MyServer" followed by "Launch Server". Then I changed the browser address from tree to lab



then I was able to run vpython programs in jupyterlab. Maybe you can try doing this. Recall what I said previously that you have to run vpython programs in either classic notebooks or jupyterlab notebooks when you run it on MyBinder. This also applies to running vpython on JupyterHub. If you run in vpython in a classic notebook and it works and then you try running vpython in a jupyterlab notebook on JupyterHub by switching the address from tree to lab is won't work. To get it to work in a jupyterlab notebook you need to perform "Stop MyServer" then "Start MyServer" then "Launch Server" in JupyterHub then switch the address to lab and then vpython will work in a jupyterlab notebook on JupyterHub. Give this a try and see if it solves your problem.


John

nibheis

unread,
Apr 23, 2020, 3:26:48 AM4/23/20
to VPython-users
Hi John,

Thanks again for the information. Here are my results:

- VPython notebooks actually work in the classic notebook environment - I had not tested before.

- I had to change the default configuration (users are sent to JLab by default). So now my hub sends me to the classic env.
- No matter how I tried to switch from one env (classic) to the other (jlab) - stopping the server, not stopping the server, etc.- I could not get VPython/JupyterLab to work in the same notebook that is working properly in classic.

Could you please explain me what is achieved by starting in classic classic mode, then stopping the server, then restarting the classic mode, then manually switching to JupyterLab ?

In my case, I am pretty sure nothing survives after the "Stop Server" step. I think even the reverse proxy configuration on the hub is deleted: on the next "Start server" the user's single user server is most probably started on another physical machine.

Not a huge leap, but I feel I am progressing on that :-) Thank you again.

Best regards,
nibheis

John

unread,
Apr 23, 2020, 9:02:49 AM4/23/20
to VPython-users
Hi nihbeis

    The VPython package running in a notebook consists of two parts, a python component running in the python kernel and a javascript component running in the web browser front end. In the classic jupyter notebook the javascript is loaded into the web page using standard web technologies. In the case of the jupyterlab notebook the javascript can only be loaded into the web page using npm package. In the jupyterlab environment you are not permitted to load javascript files using regular web browser techniques and can only use npm.

    So when you start up a jupyterhub using the classic notebook and run a vpython notebook then the vpython javascript files are loaded into the web page using standard browser methods. So once you run vpython in a classic notebook then you can't just switch to the jupyterlab environment and try running the same notebook because the vpython javascript files are already loaded into the page using standard browser methods and not by using npm. That is why I found it necessary to restart the jupyterhub server and then switch to the jupyterlab environment and then run the vpython notebook in jupyterlab so that the javascript files get loaded properly via npm only. When I do this then the vpython programs run properly in JupyterLab in the JupyterHub that I am using.

     You get a similar behaviour when running on MyBinder service that I mentioned previously. When you run vpython in a classic notebook on mybinder then you can't just switch from "tree" to "lab" in the web address and try running the same vpython program in a jupyterlab notebook. In the case of MyBinder you need to switch to "lab" mode when mybinder first comes up and then run vpython in a jupyterlab notebook in order to get it to work.

     Here is the link to running vpython on mybinder that I previously mentioned if you want to experiment with this behaviour of running vpython in a classic notebook or a jupyterlab notebook on mybinder by switching between tree and lab in the ip address bar.


      Once you run vpython in a classic notebook after binder comes up then you can't just switch to a jupyterlab notebook and run the same notebook. You will need to launch mybinder again and then switch to "lab" mode first and then run the vpython notebook in jupyterlab in order for it to work. I see a similar behaviour in JupyterHub but instead of relaunching mybinder I found that I needed to stop and restart the JupyterHub server.

John
     

John

Bruce Sherwood

unread,
Apr 23, 2020, 10:47:23 AM4/23/20
to VPython-users
John, thank you so much for the great support you are providing!

Bruce

John

unread,
Apr 23, 2020, 11:22:01 PM4/23/20
to VPython-users
Hi nibheis

    When you want to run a vpython notebook in jupyterlab check that the notebook is not already running. This is indicated in jupyterlab by a green dot to the left of the notebook file name. Be sure that the kernel for the notebook is not already running when you open the notebook. You can shut down the kernel for a notebook in jupyterlab using the menu Kernel->Shut Down Kernel or by selecting the Kernel Sessions icon on the left hand side of jupyterlab and selecting SHUT DOWN beside the vpython notebook name. I always shutdown the kernel for a notebook after running a vpython program. In jupyterlab when you close the tab for a vpython notebook the kernel keeps running, so you need to take the second step of shutting down the kernel for the notebook. If you open a notebook for vpython program whose kernel is already running and try executing the notebook then it won't display anything in the output. For a vpython notebook that you want to execute in jupyterlab you need to make sure the kernel is not already running for that notebook before you open the notebook and run it.

    In a classic notebook, after you execute the notebook and close the notebook file the kernel for the notebook is shut down automatically. However in jupyterlab, they don't shut down the kernel for a notebook when you close the notebook.

   So in jupyterlab the steps you should take to run a vpython notebook are as follows:

   1) Open the notebook file
   2) Run the notebook
   3) Close the notebook tab
   4) Shut down the kernel for the notebook.

  Also in JupyterLab you can try selecting the menu item Kernel -> Shut Down All Kernels... prior to performing the steps to reboot the server using the sequence "tree" -> Control Panel -> Stop My Server -> Start My Server -> Launch Server -> "lab" .

  Then try running a vpython program in lab ensuring that the Kernel Sessions of all the notebooks are shutdown prior to opening a vpython notebook file and executing the notebook.

  See if this works for you.

John
    


On Thursday, April 23, 2020 at 12:26:48 AM UTC-7, nibheis wrote:

nibheis

unread,
Apr 27, 2020, 12:24:07 PM4/27/20
to VPython-users
Hi John,

Thank you very much for your detailed insights and instructions.
Unfortunately, I could not get it to work with JupyterLab - most probably something specific on our side. I tried all possib;e combinations of kernel stopping and URL change and server stop... without success.

After a week of trial and errors, I now have to move on and I announced the person who requested VPython that I won't be supporting its usage on our servers.
Even if it worked following your instructions, it would a way too complicated procedure : just imagine a teacher having to support his/her 100+ students trying to switch from lab to classic to get VPython loaded, then make sure the kernel is stopped, then switch from classic to lab and open the notebook again.

Once again, your outstanding support was much appreciated !

Best regards,
nibheis

John

unread,
Apr 27, 2020, 1:32:22 PM4/27/20
to VPython-users
Hi nibheis

    I am able to run vpython in a JupyterLab notebook on JupyterHub on my system. If  vpython does not appear to work in a JupyterLab notebook then you should select the JupyterLab menu options  "Kernel-> Restart Kernel and Clear All Outputs..." . Then rerun the vpython code in the notebook to get it work properly.

    Why don't you give that a try by creating a new notebook in JupyterLab and entering the following code in a notebook cell and execute it.

    from vpython import *
    scene = canvas()
    box()

   If this works for you then you should be able to execute it over and over again and it should work. If it doesn't work then you can try select the JupyterLab menu sequence "Kernel -> Restart Kernel and Clear All Outputs..." and then execute the vpython code again. Adding the line  "scene = canvas()" is recommended for vpython programs in a Jupyter notebook.

  My previous instructions about switching between "lab" and "classic notebook" were just for debugging the problem to see if we could get vpython working in jupyterlab on your JuptyerHub and shouldn't be necessary for students or a professor to perform to get it to work on your JupyterHub. However they should be aware of the JupyterLab menu options "Kernel -> Restart Kernel and Clear All Outputs..." which is a standard thing to do in Jupyter notebooks.

John
Reply all
Reply to author
Forward
0 new messages