"wait for websocket to connect" error

140 views
Skip to first unread message

Jebb Song

unread,
Feb 25, 2022, 9:25:07 PM2/25/22
to VPython-users
Hi,

when I am using the Vpython package in Jupyterlab, I get this error:

~/.local/lib/python3.8/site-packages/vpython/with_notebook.py in <module>
151 baseObj.glow = GlowWidget(wsport=__SOCKET_PORT, wsuri='/ws') 152 while (not wsConnected): -->153 time.sleep(0.1) # wait for websocket to connect 154
155 baseObj.trigger() # start the trigger ping-pong process


I currently run:
Python 3.8.12 Jupyterlab 3.2.1-1

I have searched other answers but none have been satisfactory in solving this problem. How should I proceed?

Best,
Jeb

John

unread,
Feb 25, 2022, 11:23:41 PM2/25/22
to VPython-users
What version of vpython are you using? Did you install and enable the jupyterlab-vpython extension?

     pip install jupyterlab-vpython

then ensure that it is enabled

     jupyter labextension list

and if it is disabled you can enable it with

     jupyter labextension enable vpython

 How did you  launch jupyterlab? Are you running it from the command line?
      jupyter lab

 I tried to install the version you mentioned Jupyterlab 3.2.1-1 but was unable to .

pip install jupyterlab==3.2.1-1
conda install -c conda-forge jupyterlab=3.2.1-1

In both cases it failed and wasn't able to find the version of jupyterlab you are using.

John

Jebb Song

unread,
Feb 26, 2022, 8:27:43 AM2/26/22
to VPython-users
Hi John,

Thanks for the help. I installed jupyterlab from https://github.com/jupyterlab/jupyterlab-desktop#download

I imported the package using both:
from jupyterlab_vpython import *  
from vpython import *

and get the error:

~/.local/lib/python3.8/site-packages/vpython/vpython.py
in __init__(self, *args1, **args) ~/.local/lib/python3.8/site-packages/vpython/vpython.py in setup(self, args) ~/.local/lib/python3.8/site-packages/vpython/vpython.py in __init__(self, **kwargs) ModuleNotFoundError: No module named 'vpython.with_notebook'

John

unread,
Feb 26, 2022, 10:36:40 AM2/26/22
to VPython-users
Hi 

     In order for VPython to work in JupyterLab you need to install a jupyterlab extension for VPython. The JupyterLab Desktop App is a 3rd party application recently announced here. 


and looking at the github repository for this project I see the following issue.


with one of the responses saying

"Installing additional JupyterLab Extensions are not supported in the desktop application at the moment. We are considering adding this support in a future release."

and another saying

"Please note that prebuilt extensions are now supported since 3.2.1-2 and can be installed via pip or conda, but extension manager is still disabled as it does not support installation of prebuilt extensions yet."

You mentioned that you are using JupyterLab 3.2.1-1 so you may need to upgrade to be able to use prebuilt extensions capabilities.

You can install the jupyterlab vpython prebuilt extension with the command

    pip install jupyterlab-vpython

I don't know if this will work since I don't know if anyone has tried using vpython on the JupyterLab Desktop App.

Maybe you should try using vpython on the official jupyterlab from https://jupyter.org/  to see if you can get it working there if you can't get it to work on the 3rd party JupyterLab Desktop App.

John

Jebb Song

unread,
Feb 27, 2022, 4:50:06 AM2/27/22
to VPython-users
Hi,

I tried using a fresh jupyterlab installation, yet now the commands are not working (like name 'curve' is not defined). Should I write: from jupyterlab_vpython import *  ? I tried typing vpython and it did not work.    

Best,
Jeb

John

unread,
Feb 27, 2022, 6:45:43 AM2/27/22
to VPython-users
Hi 

     I tried installing the JupyterLab Desktop App on a linux machine and was unable to get vpython to work on it. So it is probably best to just use the official jupyterlab from jupyterlab.org since we know that works and has been tested  rather than the 3rd party software such as JupyterLab desktop app. See the installation instructions here on how to install the official jupyterlab.


Here is an example of vpython working on the official jupyterlab in the cloud using binderhub. Just click on the link and after it loads you should be able to open a number of demo vpython jupyter notebooks to run in jupyterlab.

Jebb Song

unread,
Feb 27, 2022, 12:33:56 PM2/27/22
to VPython-users
Hi John,

Sorry for the incessant questions, but I still can't seem to get it to work. Typing !pip3 list shows:
jupyterlab-vpython 3.1.3

Furthermore, typing
import jupyterlab_vpython
print(jupyterlab_vpython.__version__)

gives:
3.1.3

However, running any code gives me:
No module named 'vpython'.

Is it possible that it is because I am running python 3.7?

If anything else does not work, it's probably because the python on my mac does not work well

Best,
Jeb

John Carlson

unread,
Feb 27, 2022, 12:56:55 PM2/27/22
to vpytho...@googlegroups.com
I can’t tell from the below if vpython package is required in addition to jupyterlab-vpython.

J

--
You received this message because you are subscribed to the Google Groups "VPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vpython-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vpython-users/288184a5-e1f9-4c08-ae90-e4db9618f458n%40googlegroups.com.

John

unread,
Feb 27, 2022, 1:33:30 PM2/27/22
to VPython-users
Hi 

    To run a vpython program you only import vpython and not jupyterlab-vpython in your program.  For instance, here is a simple 3 line program to display a box.

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

     The jupyterlab-vpython is what is called a JupyterLab Extension that is used to customize and enhance JupyterLab that you only need to install one time with the command

      pip install jupyterlab-vpython

    See the following documentation about JupyterLab Extensions.


    The JupyterLab Desktop App had this issue raised regarding extensions which is still open


but they mention that they support prebuilt extensions  and jupyterlab-vpython is a prebuilt extension but it has never been tried with JupyterLab Desktop App.

    As I mentioned, the JupyterLab Desktop App that you are using is NOT the official JupyterLab software and we haven't tested or tried to integrate vpython with it. I attempted to get vpython to run on JupyterLab Desktop App but I was unable to do so. You should use the official JupyterLab instead. 

    If you are new to vpython programing, then the easiest way to get started is with  Web Vpython  at webvpython.org  ( glowscript.org ) which runs in your browser. You can see and try out many demo vpython programs here.


Just click the "Run" beside any of the demo vpython programs to run them in your browser. Or click on "View" to view the source vpython code. You can create a free  account at Web Vpython  ( glowscript.org)  so you can create your own vpython programs there and share them with others.

You can also run these same demo programs in a Jupyter Notebook as well by copying the code and replacing the 1st line of code

GlowScript 3.2 VPython

with 

from vpython import *

and then running the code in a notebook cell.

Click this link to run many of these same demo programs in Jupyter Notebooks using JupyterLab on mybinder.org.

They are the exact same code as Web VPython except the first line is replaced with

from vpython import *

for them to run in a Jupyter Notebook. So if you want to get started creating and running your own vpython programs without having to install any software then you should consider using Web VPython.

John

unread,
Feb 27, 2022, 3:16:10 PM2/27/22
to VPython-users
As a workaround of running vpython in a JupyterLab Desktop App you can embed a Web Vpython program link in an IFrame and display that. You can run the following code in a JupyterLab Notebook cell and it will display the 3D Web VPython scene.

from IPython.display import IFrame

IFrame(src='https://glowscript.org/#/user/GlowScriptDemos/folder/Examples/program/Stonehenge-VPython', width=700, height=600)

Just copy the above 2 lines in a notebook cell and execute the cell. This worked for me in JupyterLab Desktop App. So you can create Web VPython programs at webvpython.org and share them via a link and an IFrame in a JupyterLab Desktop App notebook cell.

John

Jebb Song

unread,
Feb 28, 2022, 1:03:30 AM2/28/22
to VPython-users
The error was referring to a fresh jupyterlab installation, not the desktop version. Is it some path problem? Or it does not install well with pip? (not pip3). Or maybe the python version. All other packages can be imported (e.g numpy), but it always shows the error: No module named 'vpython'

John

unread,
Feb 28, 2022, 1:29:46 AM2/28/22
to VPython-users
To get a list of installed packages and their version numbers type the command
 
    pip list

or 

   conda list

if you are using anaconda. The recommended python distribution is Anaconda and the individual edition is free.



John

Jebb Song

unread,
Mar 1, 2022, 1:56:28 AM3/1/22
to VPython-users
I have downloaded jupyterlab_vpython already. Typing pip list shows that jupyterlab_python is already downloaded. This is for the original jupyterlab, not the desktop version. However, using the python terminal, I type in help(), then "modules". I can't find the vpython module in there, but I do see the jupyterlab_vpython module. Is the package somehow not creating a vpython module?

Typing modules shows that I do not have vpython module, but I have the jupyterlab_vpython module
Screenshot 2022-03-01 at 2.53.51 PM.pngScreenshot 2022-03-01 at 2.54.40 PM.png

I really appreciate the help! I apologise if I am not clear with my questions.

Best,
Jeb

John

unread,
Mar 1, 2022, 9:56:29 AM3/1/22
to VPython-users
Hi

     You need to install both vpython AND jupyterlab-vpython if you are using JupyterLab. So you need to execute both

      pip install vpython
      pip install jupyterlab-vpython

     The installation instructions for vpython are here


      So all users who want to use vpython need to install it

      pip install vpython

      For JupyterLab users they would need to install the jupyterlab extension for vpython  (jupyterlab-vpython) in addition to vpython.

      pip install vpython
      pip install jupyterlab-vpython

      And to use vpython in a notebook cell you import vpython like in this 3 line program.
 
      from vpython import *
      scene=canvas()
      box()


      John

Jebb Song

unread,
Mar 1, 2022, 7:10:51 PM3/1/22
to VPython-users
Thanks alot for the help, it seems to work now!
Reply all
Reply to author
Forward
0 new messages