No visual output

134 views
Skip to first unread message

Karl Giroux

unread,
May 28, 2024, 8:40:54 PMMay 28
to VPython-users
Hi,
I installed VPython by running
  • conda install -c vpython vpython
  • conda install -c conda-forge jupyterlab-vpython
Then, with Jupyter Notebook, I ran
  • from vpython import *
    a=vector(2,3,4)
    b=vec(2.5,2.5,1)
    a+b
I got "vector(4.5, 5.5, 5)". So it's working.

I then ran "sphere()" and nothing happened. Most of the time. Sometimes, a black rectangular appears, with no sphere in it.

I read everything I could find, I have no clue why I can't execute "sphere()", or "box()", etc.

I tried in Spyder, in the console, it's the exact same thing...

Does anybody have a clue? Thank you very much!

John

unread,
May 28, 2024, 9:15:15 PMMay 28
to VPython-users
The first thing to check is weather or not your browser supports webgl.


If it does then you should be able to run the example web vpython programs here.


You can then check to see that these same  example vpython programs run in jupyterlab notebook in the cloud by going to this link.


If that all works then check which versions of vpython and juptyerlab and notebook you have installed.

conda list

or

pip list

and also check that the jupyterlab extensions are enabled in jupyterlab by clicking on the "Extension Manager" icon on the left side of jupyterlab interface.

Karl Giroux

unread,
May 28, 2024, 11:09:40 PMMay 28
to VPython-users
Hi John, thank you for helping me. Very appreciated!

I'm using Firefox on linux. My Firefox supports webgl as I see the animation on get.webgl.org. But it stops there : most examples of glowscript.org don't show up in my Firefox browser. The same with the programs on mybinder.org. But... and that is very interesting, if I'm using Google-Chrome, I see all the examples on glowscript.org and mybinder.org in a very fluid way.
The problem seems to be with my Firefox installation... I had a script blocker (NoScript) so I deactivated it to no avail. I'm still halted.

I could use Chrome for VPython work, but it does'nt work either: I'm asked for a password or a token whenever I copy-paste the URL from Firefox to Chrome. If I'm to switch to Chrome for Jupyter, I would set Chrome as my default Jupiter browser... I'm still trying.

John

unread,
May 29, 2024, 1:40:57 AMMay 29
to VPython-users
When you launch jupyter lab from the terminal 

   jupyter lab

you will see some output in the terminal like


    To access the server, open this file in a browser:
        file:///C:/Users/GuestUser/AppData/Roaming/jupyter/runtime/jpserver-17920-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/lab?token=94eb2845d67fcca1c1e8c117f1fb8656d5bf6cf9e4e908db
        http://127.0.0.1:8888/lab?token=94eb2845d67fcca1c1e8c117f1fb8656d5bf6cf9e4e908db

You can then just copy and past one of these http addresses into the google chrome browser's address bar and it will open jupyter lab with the required token.

Also you should be able to launch jupyter lab from the command line and specify the browser to open it in with the --browser option.

    jupyter lab --brower=google-chrome

You can use the ==help flag to see other options

    jupyter lab --help

Karl Giroux

unread,
May 30, 2024, 8:41:02 AMMay 30
to VPython-users
Thanks. So far so good. I have to select my browser depending if I'm using VPython or not, for only Google Chrome can show VPython graphics on my machine... It's annoying, I don't understand what goes wrong, but I can live with that.

But it's not working as expected. With Chrome, I can now see some shapes... once! If I need to adjust the radius of my sphere, from the second time I execute the cell which includes the graphical commands, the canvas dissapears and never reappears. This is the code I'm fiddling with :
  • from vpython import *
  • scene.width=800
  • scene.height=600
  • scene.background=vector(1,1,1)
  • ball=sphere(pos=vector(2.5,2.5,4),radius=4)
  • cuboid=box(pos=vector(-10,-3,0), size=vector(12,7.5,8), color=color.green)

 The only way is to quit altogether chrome, then relaunch it and reopen  my notebook, change the radius and execute it. That way for every cell... That can't be normal behavior. Any idea what is in cause?

Bruce Sherwood

unread,
May 30, 2024, 12:33:07 PMMay 30
to VPython-users
Not sure this is relevant, but from the installation instructions at vpython.org:

When running from a terminal, if the program does not end with a loop
containing a rate() statement, you need to add "while True: rate(30)"
to the end of the program. This is not necessary when launching from
environments such as Jupyter notebook, IDLE, or Spyder.

Bruce

John

unread,
May 30, 2024, 1:17:15 PMMay 30
to VPython-users
You should add the line

scene = canvas()    # This is needed in Jupyter notebook and lab to make programs easily rerunnable

to recreate the scene each time you execute the cell. You can just add it after importing vpython

from vpython import *
scene = canvas()
scene.height=800
scene.background=vector(1,1,1)
...

You can find documentation on the vpython canvas in the vpython documentation.


If you don't use the canvas then vpython will just use a default scene and it is only created once. To redisplay the default scene in a jupyter notebook you will need to click the "Restart the kernel" icon in the menu bar at the top of the notebook.

John

John

unread,
May 30, 2024, 1:46:14 PMMay 30
to VPython-users
With regard to vpython graphics not working in Firefox browser, you could just also try running webgl sample programs that just use webgl and javascript.


If these don't work in your Firefox browser then maybe you have webgl or javascript disabled in Firefox for certain websites.

Karl Giroux

unread,
Jun 1, 2024, 10:46:22 PMJun 1
to VPython-users
Thanks John.
scene = canvas() is a game changer! Now, everything works in Chrome, but still not in Firefox.
I would never have guessed that little line, even after reading the link you just provided about canvas. From the moment I decided to get myself into Python, I bought a lot of books, and 3 of them introduce VPython, and none explains that.
So many hours lost... At last, one problem solved.Thanks so much!

Karl Giroux

unread,
Jun 1, 2024, 11:09:02 PMJun 1
to VPython-users
All the webgl samples work superb in my Firefox. It doesn't seem to be the problem.

In case that would be relevant, I tried Spyder instead of Jupyter (Notebook or Lab, same thing) with the same code  :
    1. from vpython import *
    2. scene = canvas()
    1. scene.width=800
    2. scene.height=600
    3. scene.background=vector(1,1,1)
    4. ball=sphere(pos=vector(20,2.5,4),radius=2,color=color.blue)
    5. cuboid=box(pos=vector(-20,-3,0), size=vector(12,7.5,8), color=color.blue)
    When I execute that code for the first time, a white empty canvas opens in a new tab in Firefox, without the sphere or the box. If I execute a second time with a change (move the ball, for example), nothing happens. If I close the tab, It won't reopen, even if I execute anew the code, including with the line "scene = canvas()".

    It's really weird, it seems I'm the only one with that type of problem, I don't find anything similar on any forum threads...

    John

    unread,
    Jun 2, 2024, 9:51:26 AMJun 2
    to VPython-users
    Check that websockets are enabled in firefox. Maybe you have some ad blocking plugin that is disabling websockets. For instance see this 


    If I go to about:config in firefox and set

    network.websocket.max-connections = 3

    then I will get a behaviour similar to what you are experiencing in jupyter notebook because vpython uses websockets. The default value for "network.websocket.max-connections" in firefox on my computer was 200.

    Try temporarily disabling any plugins or extensions that you may have in firefox to see if it fixes the problem.


    John

    John

    unread,
    Jun 2, 2024, 1:57:12 PMJun 2
    to VPython-users
    You mentioned that all the webgl samples work superb in your Firefox. How about these javascript versions of web vpython programs at this link. 


    Do they work in your Firefox? They are just using webgl and javascript like the webgl samples here


    John

    On Saturday, June 1, 2024 at 8:09:02 PM UTC-7 karl.gir...@gmail.com wrote:

    Karl Giroux

    unread,
    Jun 2, 2024, 11:32:24 PMJun 2
    to VPython-users
    My default value for "network.websocket.max-connections" in firefox on my computer is also set at 200.

    I did not have many extensions, and I did disable all extensions and all plugins, including Codec vidéo OpenH264 and Widevine by Google. I restarted the browser and Jupyter. No difference. Whenever I want to do 3D, all I see is a white canvas. I can change the color of the canvas (scene.background=color.red) but no sphere or box or anything. It's the exact same behavior as before.

    Karl Giroux

    unread,
    Jun 2, 2024, 11:41:47 PMJun 2
    to VPython-users
    The animations at https://webglsamples.org/ run flawlessly. Very reactive.

    The animations at https://glowscript.org/#/user/GlowScriptDemos/folder/Examples-JavaScript/ are different. Sometimes, I see nothing, and sometimes, half of what I'm supposed to see.
    For example, with https://glowscript.org/#/user/GlowScriptDemos/folder/Examples-JavaScript/program/DancingPendulums, I see nothing but the time flying by at the bottom of the canvas.
    With AtomicSolid at https://glowscript.org/#/user/GlowScriptDemos/folder/Examples-JavaScript/program/AtomicSolid, I see all the coils but not the spheres (ah-ha! maybe we touch something...)
    With the gyroscope at https://glowscript.org/#/user/GlowScriptDemos/folder/Examples-JavaScript/program/Gyroscope, I don't see the gyroscope, but I see the green path being drawn.

    So it's like I see some of it...

    John

    unread,
    Jun 3, 2024, 10:46:09 PMJun 3
    to VPython-users
    I created a virtual linux machine and installed firefox browser on it and reproduced the problem. I find that the only webvpython objects that get displayed are curve objects. For instance the rotating curve example program looks like it works in firefox on linux.


    So there seems to be an issue with displaying vpython objects in webvpython programs in firefox browser on linux machine.
     
    If I use google-chrome browser on the linux virtual machine then the webvpython example programs all work. So the workaround for now is to just use google-chrome browser for vpython on a linux machine.

    I created the virtual linux machine on my Windows computer using Windows Subsystem for Linux (WSL). I will note that if I run Firefox under Windows OS then vpython works fine in that case, it's only when you run Firefox on Linux where the problem occurs.

    Also the problem was reported in the webvpython forum previously in this thread.

    Ken Burns

    unread,
    Jun 4, 2024, 12:54:42 PMJun 4
    to VPython-users
    Could be due to sandboxing, depending on how Firefox was installed?

    John

    unread,
    Jun 4, 2024, 5:50:24 PMJun 4
    to VPython-users
    I am not that familiar with sandboxing of browsers. I found this article


    With my testing of browsers on a virtual Linux machine using Windows Subsystem for Linux (WSL) I found that the webvpython example programs all worked with google-chrome, microsoft-edge and opera browsers on WSL but did not work with the Firefox browser on WSL. 

    Ken Burns

    unread,
    Jun 4, 2024, 10:00:16 PMJun 4
    to VPython-users
    Yes, that article describes sandboxing, and addresses the sandboxing that each browser internally enforces.... these can likely be configured?

    Here is a link that addresses configuring sandboxing within the browser: https://www.thewindowsclub.com/what-is-browser-sandbox , you can likely find other sites.

    But, you you can get an additional layer of sandboxing based on what file you chose when installing Firefox.  Snap, Flatpak and AppImage are all popular ways to install Linux apps (and you may have used none of them).  All three of these add an additional layer of sandboxing (as a feature!).  The three differ in the sandboxing they provide, and some are configurable at the time of app installation.

    This can get pretty deep pretty fast.  Suggest you see if Firefox is available directly from your Linux distribution's default repository, using a file that does NOT have snap, flatpak or AppImage anywhere in the package name.. If so, then uninstall the Firefox you have installed and try that one, as it is unlikely to add an additional layer of sandboxing.

    And/Or, see if you can select WebGL to be installed with Firefox.  (Note this needs to be WITH Firefox, not a separate installation).  This would put it in the same sandbox.

    John

    unread,
    Jun 5, 2024, 11:12:33 AMJun 5
    to VPython-users
    I tried uninstalling Firefox and reinstalling it a few times on my Linux virtual machine ( Windows Subsystem for Linux  ) using different installation instructions provided here.


    and find the the problem is still present in Firefox after each install. So for me on my virtual Linux machine, it seems that you can't run webvpython programs in Firefox. I haven't tested with a non virtual Linux machine so maybe it will work properly in that case.

    However webvpython worked fine on my virtual Linux machine with all the Chromium based browsers that I tried ( Chrome, Microsoft-Edge, Opera, Brave). 

    John

    unread,
    Jun 5, 2024, 1:56:07 PMJun 5
    to VPython-users
    Firefox is a Gecko-based browser according to


    I tried running webvpython using the LibreWolf browser on my virtual Linux machine and it didn't work either. LibreWolf is also Gecko-based and looks like a derivative of Mozilla-Firefox according to the above link. So perhaps all Mozilla-Firefox based browsers will have this problem or maybe even all Gecko-based browsers. However webvpython worked on all of the Chromium-based browsers that I have tried in my virtual Linux machine.

    Karl Giroux

    unread,
    Jun 6, 2024, 8:33:03 AMJun 6
    to VPython-users
    You are amazing, Sir! Huge thanks! You made me learn a lot. VPython has been around for several years, so I'm surprised that "bug" wasn't documented anywhere (that I could google). Now, thanks to you, it is.

    In real life, I'm a physics teacher, and I wanted to learn VPython to help some students to visualise some 3D problems by handling basic shapes. All these difficulties that we encountered are adding up, and I'm concerned It's not a "one size fits all" thing anymore.

    Maybe I should try with a web-based VPython... maybe it would work with every browser. I know it's not the subject of this thread, but do you have a suggestion? Trinket? It's all new to me.

    Joe Heafner

    unread,
    Jun 6, 2024, 1:27:13 PMJun 6
    to Users VPython
    I have been monitoring this thread and have this to offer.

    First, VPython in Jupyter Lab works perfectly with Firefox on macOS Sonoma. I'm sitting here running it right now (screenshot attached) and did for a number of years after moving away from Chrome. It does not work in LibreWolf and I would not expect it to because LibreWolf is a fork of Firefox that is heavily modified for privacy and security and I don't think it's worth troubleshooting LibreWolf. WebVPython (formerly known as GlowScript) also works just fine in Firefox and always has.

    Second, there are problems with conda-forge packages that have not existed before. I've spent the past two days experimenting with various installation procedures that I would have thought would be equivalent but they are not. I too ended up with a non-functioning installation on my M1 iMac and M3 MacBook Air when I tried to separately install VPython. I got error messages saying sphere() wasn't defined (screenshot attached) despite not getting an error message for "from vpython import *". Something somewhere in the conda workflows has broken for Arm Macs and I have no knowledge of how to troubleshoot such things.

    Sitting here just now, I did this:

    conda create --name testing python=3.12
    conda activate testing
    conda install -c vpython vpython

    and it failed with an error message about "no viable options". Screenshot attached.

    conda install -c conda-forge vpython

    and it worked for installation, but only Jupyter Lab gets installed, not Jupyter Notebook, which apparently is related to the sphere() error because because note that the notebook module is missing.

    I finally had to create an environment by manually installing both Jupyter Notebook and Jupyter Lab from scratch and then installing vpython on top of that. I've tried so many combinations that I can't determine whether I used "conda install -c vpython vpython" or "conda install -c conda-forge vpython", but according to "conda list" I apparently used "conda install -c vpython vpython".

    The bottom line is that something somewhere in the conda workflow has changed and I have no idea what it is or how to find it and fix it.


    Joe Heafner
    Sent from one of my Macs

    Screenshot 2024-06-06 at 12.19.02.png
    Screenshot 2024-06-06 at 12.57.43.png
    Screenshot 2024-06-06 at 13.03.50.png

    John

    unread,
    Jun 6, 2024, 1:50:56 PMJun 6
    to VPython-users
    I wasn't aware of this issue with running VPython in Firefox on Linux until you brought it up. Vpython works fine in Firefox on my Windows 10 machine. I was only able to test it with Firefox and Linux on a virtual Linux machine. Maybe it works fine on a dedicated Linux PC rather than a virtual one.

    Here is some information on Browser market share and OS market share which you can filter for different platforms (All, Desktop, Tablet, Mobile).



    So for desktop platform, according to above links, Linux has about 3.7% market share and Firefox has 6.5% market share in desktop market. So maybe that is why this issue hasn't been noticed before.

    I am not a teacher so I will let others who have experience teaching make suggestions. I don't have any usage stats of vpython in education but I believe that webvpython is a popular choice.

    John

    unread,
    Jun 6, 2024, 2:01:59 PMJun 6
    to VPython-users
    The classic Jupyter Notebook is being replaced by the new Jupyter Notebook 7 . See these articles for what the changes are.




    If jupyter notebook is not working for you then make sure you have JupyterLab 4.x and Notebook 7.x installed with VPython 7.6.5. Use the command

    conda list

    to see what versions of the packages you have installed. You might need to install Jupyter notebook separately, it might not be installed with JupyterLab.

    conda install -c conda-forge notebook

    Bruce Sherwood

    unread,
    Jun 6, 2024, 2:40:17 PMJun 6
    to VPython-users
    Karl, since you are a physics teacher, I want to say VERY STRONGLY that if any of your students are new to programming they definitely should be using Web VPython (webvpython.org or trinket.io). Students with little or no programming experience have a lot of trouble dealing with installing software and understanding folders and files and file extensions.

    Historical note: Prior to 2015 the only way to use VPython was to install Python and the VPython module. Georgia Tech was the first institution to switch (in 2015) to Web VPython, and they reported a huge improvement in students' attitudes toward and acceptance of VPython. We had not fully realized how big a barrier software installation had been for students.

    Recently some instructors have been encouraging students to use Web VPython rather than a calculator when doing homework. This increases students' familiarity with programming, makes vector calculations much easier, encourages students to use symbols in their calculations (to capture intermediate results), and makes it much easier to find and fix errors in a long calculation. Some instructors have even made it possible for students to use Web VPython during exams, using a "lockdown" browser or other mechanism, and students can show their work by turning in their program, which has the advantage that it is much easier to read a program containing symbols than handwritten scribbles.

    Another mechanism instructors have used to give students more exposure to programming is to use Web VPython themselves in class rather than writing their calculations on the blackboard; this is sometimes called "live programming". Among other benefits, one can't avoid occasionally making mistakes, which shows students that this is normal and unavoidable, not something to be ashamed of. All of this gives students lots of time on task to help them become comfortable with computing.

    For an example of "live programming" go to https://www.youtube.com/watch?v=FYz6-ckSCdo and scroll to the time 38:45. You will see Ruth Chabay while teaching remotely using Web VPython to calculate the electric force between two charges, modeling this approach to calculations. This is early in the first-semester course (mechanics), and she does a bit of propaganda at the end, pointing to the advantages of calculating using this tool.

    Bruce

    Joe Heafner

    unread,
    Jun 6, 2024, 5:07:42 PMJun 6
    to Users VPython


    > On Jun 6, 2024, at 14:01, John <john...@shaw.ca> wrote:
    >
    > The classic Jupyter Notebook is being replaced by the new Jupyter Notebook 7 . See these articles for what the changes are.
    >
    > https://blog.jupyter.org/announcing-jupyter-notebook-7-8d6d66126dcf
    >
    > https://blog.jupyter.org/jupyterlab-4-1-and-notebook-7-1-are-here-20bfc3c10217
    >
    > https://blog.jupyter.org/jupyterlab-4-2-and-notebook-7-2-are-available-b5e6b3c753de

    Yes I am aware of all this, but it is not relevant to the issue at hand.

    > If jupyter notebook is not working for you then make sure you have JupyterLab 4.x and Notebook 7.x installed with VPython 7.6.5. Use the command
    >
    > conda list
    >
    > to see what versions of the packages you have installed. You might need to install Jupyter notebook separately, it might not be installed with JupyterLab.
    >
    > conda install -c conda-forge notebook

    Yes, but this is not documented on the VPython home page installation instructions. Doing "install -c conda-forge vpython" also installs Jupyter Lab, but results in a nonworking installation because the notebook module is required (see screenshot of the sphere() error). Doing "install -c conda-forge jupyterlab-vpython" as instructed is superfluous and does nothing, giving the resulting message "#All requested packages already installed." The vpython installation obviously requires the notebook module so it should be included in the dependencies, but it apparently is not. There is no mention in the instructions of having to install it manually and I don't think a new user should be expected to know that. I'm a decades-long user and didn't expect it. Everything used to "just work" on my Macs and now it doesn't. This is a problem. I just confirmed that doing "install -c conda-forge notebook" indeed fixes the problem.

    Summary: The default vpython install apparently requires the notebook module to be present but does not install it as a dependency. Only Jupyter Lab is installed. The install instructions reference Jupyter Notebook without disclaiming that it now apparently must be installed separately. Either the notebook module should be installed as a dependency or it should not be needed for running VPython under Jupyter Lab. I think this will create problems for users.

    Apologies if I am not being clear in explaining the problem. I am trying as hard as I can.

    I will continue working on the infinite update/downgrade loop introduced by "conda update --all" command.

    Bruce Sherwood

    unread,
    Jun 6, 2024, 7:48:34 PMJun 6
    to VPython-users
    Joe, can you propose specific modifications to the installation instructions given at vpython.org?

    Bruce

    John

    unread,
    Jun 6, 2024, 9:05:09 PMJun 6
    to VPython-users
    You are right, I did some testing with the command  "install -c conda-forge vpython" and it did not install the notebook package. So if installing from conda-forge then an extra step of

    conda install -c conda-forge notebook

    is required in the install instructions. If you do a pip install of vpython then jupyterlab and notebook packages got installed properly. Also  "install -c vpython vpython" command is not working correctly, it is installing a previous version of vpython rather than the latest version 7.6.5.

    I tested this out by creating a separate python environment with the command

    conda create -n vpy3.12 python=3.12 pip

    then I activated the environment with the command

    conda activate vpy3.12

    Then I pip installed vpython into this sandboxed python environment.

    pip install vpython

    and it correctly installed vpython, jupyterlab and notebook packages as well as others. Both commands

    jupyter lab

    and 

    jupyter notebook

    worked and I was able to run vpython 7.6.5 in the jupyterlab and jupyter notebook browser interfaces.

    Then I deactivated the environment 

    conda deactivate

    when I was done testing.

    I created a similar python environment with a different name to test "install -c conda-forge vpython"  and found that in order for vpython to work properly I needed to add the command "conda install -c conda-forge notebook".

    However in the case of testing  "install -c vpython vpython" in a separate python environment it failed to install vpython 7.6.5. So I do not recommend using this last command to install vpython.

    John Carzoli

    unread,
    Jun 7, 2024, 1:59:51 AMJun 7
    to vpytho...@googlegroups.com
    I had the same issue as Joe in that Jupyter Notebook wasn't initially installed. The following are the commands I used to get things working nicely:

    conda create -n py312 -c conda-forge


    conda install -n py312 -c conda-forge python


    conda install -n py312 -c conda-forge vpython


    conda install -n py312 -c conda-forge jupyterlab-vpython


    After running this it said that "All requested packages already installed"


    conda install -n py312 -c conda-forge notebook


    After all this everything works well. After each entry I did a "conda list" so I could compare what was installed, but I haven't included that output here.


    John



    John Carzoli, Ph.D.
    Distinguished Professor, Physics
    Division of STEM and Health Careers
    1600 E Golf Road
    Des Plaines, IL 60016



    On Thu, Jun 6, 2024 at 6:48 PM Bruce Sherwood <bruce.s...@gmail.com> wrote:
    Joe, can you propose specific modifications to the installation instructions given at vpython.org?

    Bruce

    --
    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/8c2ce314-8e0b-4d75-b8e6-150998f3d511n%40googlegroups.com.
    Reply all
    Reply to author
    Forward
    0 new messages