Is vpython compatible with PyScript?

45 views
Skip to first unread message

Mark Somers

unread,
May 11, 2024, 5:02:06 AMMay 11
to VPython-users
I am interested in incorporating vpython simulations into MyOpenMath.  While students are manipulating a vpython simulation, I want to use MyOpenMath to ask them questions about the simulation.  I also want MyOpenMath to verify that students have correctly set the controls in the vpython simulation.  

I have written a number of javascript simulations and have successfully integrated them into MyOpenMath.  MyOpenMath questions consist of a code window and an html window.  Javascript code is placed inside of a script tag in the html portion of a MyOpenMath question.    

I am hoping to do something similar with vpython.  PyScript is supposed to allow python code to be placed inside of html.  However, I have been unsuccessful at running a simple vpython program in PyScript.  When I try, I get the following error in the console:

pyodide.asm.js:9 Uncaught (in promise) PythonError: Traceback (most recent call last):
File "/lib/python3.11/site-packages/micropip/_commands/install.py", line 146, in install
    raise ValueError(
ValueError: Can't find a pure Python 3 wheel for: 'vpython'
See: https://pyodide.org/en/stable/usage/faq.html#why-can-t-micropip-find-a-pure-python-wheel-for-a-package

I have a good deal of experience in javascript, but am new to python, vpython and PyScript.  Hence, I am not sure how to proceed after seeing this error message.  Any help would be appreciated.

Steve Spicklemire

unread,
May 11, 2024, 5:24:02 AMMay 11
to 'Ian Beatty' via VPython-users, Steve Spicklemire
Hi Mark,

I know nothing about PyScript, but vpython is not a pure python package. I’m assuming PyScript is based on pyodide, the wasm version of python? There is an effort to begin beta testing a pyodide based version of WebVPython soon, probably this summer. It may be that this would be something that could work with PyScript projects? I’m not sure, but it’s possible. Please stay tuned!

-steve
> --
> 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/a0107ce2-5492-4231-b4e0-f489e249476fn%40googlegroups.com.

Bruce Sherwood

unread,
May 11, 2024, 12:19:47 PMMay 11
to VPython-users
You may find it useful to view this overview of the architecture of VPython:


The following may also be of interest:


Bruce

Bruce Sherwood

unread,
May 11, 2024, 1:58:56 PMMay 11
to VPython-users

Mark Somers

unread,
May 11, 2024, 10:02:02 PMMay 11
to VPython-users
Thanks for the feedback.  I'll definitely be checking in.  If you hear of anyone else who it trying to integrate vpython with MyOpenMath, I'd definitely be interested as well.  
Thanks!
Mark

Mark Somers

unread,
May 11, 2024, 10:10:54 PMMay 11
to VPython-users
I just saw Bruce's note about running running VPython in JavaScript.  That should be workable,  I had written a program in VPython that I'll work to convert to JavaScript.  I had hoped, however, to be able tap into the large library of existing VPython scripts.  Hence, I'll still be interested in future developments in the Python side.  Thanks again.
Mark

John

unread,
May 13, 2024, 8:56:00 AMMay 13
to VPython-users
You can automatically generate the javascript code of any of the webvpython example programs.


Just click on the "View "  link for any of the demo programs to view the webvpython source code. Then click on the "Share or export this program  " link which will take you to a page like this with the different share options.


You have the option to copy the code in the box into your webpage.

Mark Somers

unread,
May 13, 2024, 6:57:06 PMMay 13
to VPython-users
Very interesting!  This looks to be extremely useful.  Thanks for letting me know! 
Mark

John

unread,
May 14, 2024, 1:03:35 AMMay 14
to VPython-users
You can try it out on these javascript example programs.


and also on the webvpython example programs 


Just go to " View -> Share or export this program " to get the javascript code of the selected example program which you can then download or share.

John
Reply all
Reply to author
Forward
0 new messages