New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
plotting from ipython #769
Comments
Hi, sorry for the late reply, have you tried:
|
Hi, great library but I just ran into the same issue. While setting the default backend to VTK solves the problem, is there an explanation why vedo defaults to "2d" in an ipython REPL? vedo --info
# vedo version : 2024.5.1 (https://vedo.embl.es)
# vtk version : 9.3.0
# numpy version : 1.23.5
# python version : 3.10.14 | packaged by conda-forge | (main, Mar 20 2024, 12:45:18) [GCC 12.3.0]
# python interpreter: /home/paul/src/miniconda3/envs/brainrender_dev/bin/python3.10
# installation point: /home/paul/src/miniconda3/envs/brainrender_dev/lib/python3.10/site-packages/v
# system : Linux 5.4.0-148-generic posix x86_64
# k3d version : 2.16.1 When running from shell: python -c "import vedo; print(vedo.settings.default_backend)"
# vtk When running in an IPython REPL:
Presumably there are good reasons for the switch, but maybe it's worth raising a warning whenever the '2d' backend is selected automatically? It took a hot minute to narrow the issue down to a ipython-vedo interaction. |
Hi - yes indeed there is a "good" reason ... the visualization part is normally delegated to an opengl graphic rendering which pops up in a separate window. |
Hi, I think there is some confusion here with Jupyter notebooks (which used to be called IPython notebooks). |
Oh OK sorry! self.default_backend = "vtk"
try:
get_ipython()
self.default_backend = "2d"
except NameError:
pass is there a way to distinguish or separate the case of a REPL vs jupyter env? |
A couple of solutions have been discussed on Stackoverflow. The first answer looks reasonably robust and works on my machine: def is_notebook() -> bool:
try:
shell = get_ipython().__class__.__name__
if shell == 'ZMQInteractiveShell':
return True # Jupyter notebook or qtconsole
elif shell == 'TerminalInteractiveShell':
return False # Terminal running IPython
else:
return False # Other type (?)
except NameError:
return False # Probably standard Python interpreter So the snippet above would be: if is_notebook():
self.default_backend = "2d"
else:
self.default_backend = "vtk" |
Also note the comment below that answer on detecting google colab notebooks: get_ipython().__class__.__module__ == "google.colab._shell" Though is suspect that vedo is probably incompatible with colab anyway due to the lack of display parameters? |
Thanks a lot Paul! This is very useful!
in fact you can run vedo in a colab env using this. |
Mitigate issue #769: don't set backend to '2d' in IPython REPLs
Hi,
Thanks for the nice tool.
I have tried to search the documentation for the way to plot form within ipython.
Is this possible? I tried several backends but none is creating a window.
Thanks
The text was updated successfully, but these errors were encountered: