Hi there
this is 2020, and is there anyway to use Numpy, SciPy, Matplot, Pandas libraries in Grasshopper’s Python!?
What’s the practical way to have these libraries in GH!?
Best regard
Zana
Hi there
this is 2020, and is there anyway to use Numpy, SciPy, Matplot, Pandas libraries in Grasshopper’s Python!?
What’s the practical way to have these libraries in GH!?
Best regard
Zana
Hi @Zana,
Indeed it is.
Here @Dancergraham explains well, how to handle a very similar case.
Regards.
loool because the most topic that I was searching on the Internet was roughly two or three years ago. I suppose that maybe there is another new practical way published recently.
But it seems that unfortunately, it doesn’t work for me.
What do you want to do?
I wanna just have these libraries in Gh’s Python to execute my algorithm that depends on these libraries modules
Have you tried GH_CPython, yet?
Also depending on your process, you could trigger an external cpython script - unrelated to the GH_CPython plugin - with for instance the subprocess
module, make it execute a task, and then import the processed, lower level data (i.e. text) back into Grasshopper, where you would parse it into something usable (i.e. point geometry).
Yes I would love to have scipy and python available in a standard Rhino (not GH) python script but I am currently using Cpython externally for the calculations and interfacing with Matlab and Ironpython in Rhino to interact with the geometry, using csv files in between the two.
-Graham
I can say, No, I’ve just tested the GHremote that I found it too weird to use.
I’m going to download and test CPython as you said. Furthermore, I did not understand what is the way and processes you mentioned, I wonder if you could explain more or maybe if I have a sample it will be so useful.
Sincerely
Thanks, @Dancergraham, you mean that you make a connection between Python in Rhino and Matlab?! How it can be possible?
I didn’t get, are you using these libraries totally in python of Rhino!? Not in GH? Please correct me if I am wrong.
Hello. for instance I save Matlab and excel files from Matlab. I use scipy and pandas in CPython to process them and write csv. Then I read the csv files into Ironpython in Rhino.
I think @Dancergraham illustrated a pretty neat and straighforward example above.
For what I was writing about, you’d need three different scripts/programs:
An external cpython script with your algorithm that is able to process relevant data outside of Rhino/Grasshopper, and uses Pandas, NumPy, etc. This should be a shell tool (executable Python script) that can accept relevant arguments from the command line (i.e. my_script -a argument
). It should also output the data, once processed, into some sort of low level file (TXT, CSV, YAML, XML, etc.).
A second GHPython script that invokes and passes parsed Grasshopper data to the cpython script, mentioned above, in the first place. Remember the latter should be executable and accept some low level arguments, so you’d be able to call it with the IronPython subprocess
module from Grasshopper.
To be clear, this GHPython script parses your Grasshopper data and sends it to the other script for processing.
Last but not least, you’d need another GHPython script that imports the saved, processed data, converts it to a Grasshopper type of information and outputs it to the canvas for further processing.
I really appreciated for your guidance both @Dancergraham and @diff-arch !!! I suppose understand what should I do.