Jupyter Notebook in Grasshopper

Hi!

Has anyone managed to run Jupyter Notebook from grasshopper? I.e. triggering a certain .ipynb file to run, and then receiving its output?

You can export your notebooks as py files and refer to the py files from grasshopper.

Using GH Python Remote? Or is there another way?

If you want access to cpython like your pandas or numpy etc, then you can use Gh_cpython from food4rhino or remote. I believe there are other solutions also - the newest ladybug tools uses python 3 in grasshopper afaik.

If you don’t need those libraries, then you can load your .py file using import statements in your gh_python component

I have other dependencies for the Jupyter notebook code, and they don’t seem to work with GH_cpython or remote, unfortunately
I wonder if there is a way to execute the jupyter code without having to run it in grasshopper

Hello,

When I have done things like this I have run my Jupyter notebook separately, saving the results to a csv file or similar, then loaded the results inside Rhino. Obviously that is not ideal if there is a lot of interraction between your geometry and your python code.

1 Like

In that case, save the jupyter notebook as a .py file somewhere on your drive.

Have a gh python script to run the bash/cmd using subprocess to run the python script in the background (basically calling “python3 your path/yourfile.py” as a windows subprocess).
And then check wherever your results should land using readfile afterwards.

import subprocess
subprocess.call(‘python3 path/file.py’)

1 Like

This works so well, thank you very much!

Hey,

I know it’s not the answer to your question, but I also wanted to connect both (Grasshopper and JupyterLab). If you have any video how it works for you then it would be really helpful if you could show us :slight_smile:
What I did was basic file export, so I could export data from JupyterLab to Grasshopper and from Grasshopper to JupyterLab: https://www.youtube.com/watch?v=ccvalWGqsGw
But if you find more elegant solution - let me know :slight_smile: