Skip to content
June 27, 2011 / stevebaer

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.
numpy_paths

Check the “Frames Enabled” option since numpy/scipy requires this to be turned on.
numpy_frames
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/

14 Comments

Leave a Comment
  1. Lluis / Mar 23 2014 11:49 pm

    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?

  2. Tim / Sep 30 2014 12:44 pm

    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?

  3. starsky62 / Oct 16 2014 10:12 am

    Hello steve. the link http://www.enthought.com/repo/.iron/. could tell the instructions how to install numpy in ironpython firts

  4. JJJ / Dec 27 2014 8:45 pm

    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!

  5. Ester / Jun 10 2015 2:04 pm

    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

    • stevebaer / Jun 10 2015 5:13 pm

      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.

  6. Nicholas Desbiens / Jul 7 2015 6:12 pm

    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

  7. Jose Holguin / Aug 25 2015 5:59 pm

    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

    • stevebaer / Aug 25 2015 6:28 pm

      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

      • Jose Holguin / Aug 25 2015 6:33 pm

        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!

      • stevebaer / Aug 25 2015 6:37 pm

        Sorry, I would ask on discourse to see if anyone there can help

  8. Mehrad Mahnia / Jul 6 2016 9:28 am

    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?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: