Numpy and Scipy in RhinoPython
Disclaimer: I have very little experience with numpy and scipy so you are going to do better by searching google for support with these libraries. This blog is about getting these libraries to run in Rhino.
Yes it is possible now!!!
Okay, here’s what I did to get numpy/scipy running in Rhino
1 – Install Rhino 5 (32bit version)
numpy/scipy uses C++ DLLs which need to be compiled for a specific platform. Currently numpy/scipy for IronPython will only run in 32bit applications on Windows. I contacted the guys at Enthought and they do plan on releasing a 64bit version for Windows, but they want to make sure everything is working on 32bit first. They have some doubts about being able to release a mono version for you Mac guys out there.
2 – Install numpy/scipy for IronPython
Follow the instructions on this site http://www.enthought.com/repo/.iron/
3 – Modify settings in RhinoPython
Start Rhino 5 – 32bit version and run “EditPythonScript” to bring up the editor. Go to the options dialog by selecting Tools->Options from the menu
Add site-packages and DLLs to the search paths (see image). This helps RhinoPython find the numpy/scipy packages and associated DLLs.
Check the “Frames Enabled” option since numpy/scipy requires this to be turned on.
I decided to make the “Frames Enabled” an optional engine feature since it does have a performance impact on scripts. Numpy/scipy requires this feature to be turned on.
4 – Run a test
# For now, we need to manually load mtrand before using numpy or scipy # I'm still trying to figure out why mtrand is not automatically getting # loaded when numpy/scipy imports it. If I can fix this, we won't need # the following two lines import clr clr.AddReference("mtrand") import numpy import rhinoscriptsyntax as rs x_coord = [ 0, 1, 2, 3, 4, 5, 6] y_coord = [0.0,0.1,0.5,2.5,2.5,2.5,4.0] xyz = zip(x_coord,y_coord,[0]*len(x_coord)) rs.AddPoints(xyz) degree = 5 eq = numpy.polyfit(x_coord, y_coord, degree) fitfunc = numpy.poly1d(eq) fit_points = [] for i in range(61): x = i/10.0 y = fitfunc(x) fit_points.append((x, y, 0)) rs.AddPolyline(fit_points)
If you get a polyline in rhino fit through a series of points then you are all all set; if not go back to step 1 and repeat.
This looks like a good place to start if you want to learn more about numpy/scipy
http://docs.scipy.org/doc/
Hello Steve,
Thanks for this post.
Do you know if Numpy is still only working for 32 bit Rhino?
Is there access to the library SymPy from RhinoPython?
I haven’t heard of a 64 bit release. You may want to contact enthought (https://www.enthought.com/) about this.
Hey, thanks for the post. I am trying to follow it, however the link http://www.enthought.com/repo/.iron/ is broken.
I found this one but not sure if it is the same thing https://github.com/numpy/numpy-refactor/wiki/Recompile
Eitherway, when I am trying to compile “ipy iron_setup.py”
I get many many errors of the form
Error 2 error C2143: syntax error : missing ‘;’ before ‘<' C:\Program Files (x86)\IronPython 2.7\numpy-refactor-refactor\numpy\random\mtrand\mtrand.cpp 246 1 mtrand
Error 3 error C4430: missing type specifier – int assumed. Note: C++ does not support default-int C:\Program Files (x86)\IronPython 2.7\numpy-refactor-refactor\numpy\random\mtrand\mtrand.cpp 246 1 mtrand
on cpp code such as
static CallSite< System::Func^ >^ __site_call0_4297_19;
…
I posted a question on stackoverflow here, which describes it in a bit more detail
http://stackoverflow.com/questions/26104455/compilation-error-numpy-refactor-in-ironpython-using-visual-studio
Have you seen anything like this?
Hello steve. the link http://www.enthought.com/repo/.iron/. could tell the instructions how to install numpy in ironpython firts
Hi Thanks for the post. The link http://www.enthought.com/repo/.iron/ seems not working any more. Any idea where esle to find instructions?
Numpy package is available only after login! http://www.enthought.com/repo/.iron/ I don’t understand how to install numpy into Rhinoceras Ironpython there is no ipy to run, please help!
Hi! I am trying to follow the instructions on http://www.enthought.com/repo/.iron/, but I want to install it for ironpython and the instructions appear just for python. Any ideas how to install iron_setup.py? I am trying
ipy iron_setup.py build
but getting errors:
error MSB4019: The imported project “c:\Microsoft.Cpp.Default.props” was not found
ideas?
Ester
It has been a long time since I’ve tried to install numpy for Rhino.Python. I would contact the guys at enthought to see if they have any suggestions. Sorry for not being more helpful.
Ester, if you gain any wisdom from the people at enthought, please share. I’ve gone down this road a few times since Steve’s original post, but without much luck.
Thanks!
Nick
Hi Steve, Thank you so much for the tutorial. I managed to install numpy and scipy on rhino 32-bit. Now, I am trying to install pyhull too for convexhull calculations. Do you know how to do this? Thank you so much
I don’t have experience with this module, but this post on discourse may help
http://discourse.mcneel.com/t/pyhull-in-rhino-python/12428
Thank you for the super quick reply. I have tried that link but no luck on how to install it. The reason I am doing that was because the spatial module of scipy doesnt appear for my on Rhino Python. Or am I doing something wrong when importing scipy into python? Thank you!
Sorry, I would ask on discourse to see if anyone there can help
Hi Steve
Thank you for the tutorial … i tried to add numpy to my rhino python but every time i run the script the following error appears, both on 64bit and 32bit versions:
Message: Could not add reference to assembly mtrand
I checked the paths added to the “Module Search Paths” and it seems that nothing has been added to the folders after installing Canopy. Is this the problem and should i add numpy folder to the location manually?