Search code examples
pythonvpython

VPython no output


I just managed to install the vpython libraries on Python 3.7, now when i run a code like this:

from visual import *
redbox=box(pos=vector(4,2,3),size=(8,4,6),color=color.red)
ball=sphere(pos=vector(4,7,3),radius=2,color=color.green)

I get this:

Traceback (most recent call last):
File "C:/Users/Deku/AppData/Local/Programs/Python/Python37/draft.py", line 1, in <module>
from visual import *
ModuleNotFoundError: No module named 'visual'

Now, when i try this:

from vpython import visual

I get this:

Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
from vpython import visual
ImportError: cannot import name 'visual' from 'vpython' (C:\Users\Deku\AppData\Local\Programs\Python\Python37\lib\site-packages\vpython\__init__.py)

How do i get this thing to run properly and do what its supposed to? The documentation on the VPython page doesn't help that much, since the examples it gives even start as "from visual import *" which doesn't seem to work.

Note: On top of that, i tried the first piece of code, but replaced "visual" with "vpython" and when the code run, it opened a page on my main browser. The link address on top reads: "http://localhost:52397/" but nothing shows or happens.


Solution

  • Just try using vpython.

    from vpython import *
    

    in the latest version of vpython they changed the import module.

    If this also doesn't work it might be related to your IDE. For example, new version of vpython still doesn't work in Jupyter Lab.