# Why can't I use NumPy in Rhino Mac

Hi!
I’m using Rhino for Mac and writing python scripts in Atom. Recently I tried to use Numpy in the scripts, but got “there is no module named numpy”, not working like Rhino 5 on the Windows. Am I missing something, since I can run Numpy on python in Terminal? It would be a great help if someone has successfully linked numpy to Rhino for Mac and willingly to share the experience!
Thanks, pyghrh.

The version of python that is embedded in Mac Rhino is IronPython. This version is not compatible with numpy on Mac, sorry.

I’d like the sinc(x) function to make a cochleoid spiral and was looking to use NumPy to get this. It’s available in Grasshopper.

Hi Mark

unless you need extremely high precision close to x==0, this should work well for you:

``````import math
def sinc(x):
if x == 0: return 1.0
return math.sin(x)/x
``````

http://mathworld.wolfram.com/SincFunction.html

## Giulio

Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

Has there been any change in the last 1 year+ that will allow NumPy module to be used from Rhino Mac python scripts? Will there be any effort put towards this in the future? I am wanting to employ linear algebra/matrix functions that I cannot seem to find. Not found in GrassHopper for Mac, either, which would be really slick there.

Second and last post are perhaps interesting.

wow. looks like a deep rabbit hole.

There are a lot of linear algebra and matrix type functions in Rhino itself. If I knew better what you are trying to do, we can probably just add equivalent functionality to RhinoCommon.

Hi Steve. Thanks for getting back to me.

Immediate issue is solving 5 simultaneous equations - standard linear algebra problem: [A] {x} = {B}; given [A] and {B}, solve for {x}. This morning, one of the Forum contributors pointed me to his very slick Gaussian Elimination routine, which looks useful for this particular issue. However, I can see that many of the functions in Python numpy and scipy libraries could be useful in the future if they could be accessed (or duplicated in RhinoCommon). I am just 1 month into learning Rhino, GrassHopper, and Python (on a Mac), so I am sure I will discover many new and interesting problems to solve with these wonderful tools!

The Gaussian Elimination routine described within the link you provided worked great for my immediate problem. Thanks.

Matt3,
Where is this Gaussian Elimination routine? I could use it in my work.

Hi Steve,
Two cents-worth on this old thread.
" If I knew better what you are trying to do, we can probably just add equivalent functionality to RhinoCommon."
That’s a very generous offer, but if I may say so it is a very limiting philosophy. Half the value of a programming interface - python, VB, C++ or whatever - is that it enables scripting of the parent app (Rhino). in ways that the authors have foreseen.
The other half is to enable any (literally) functionality which is available from that language. The C++ API provides this, so it is the fall-back for more complex plug-ins. IronPython seems to have limited scope in the Python world. (eg no numpy), which limits its use to Rhino scripting. If you want Python eventually to supercede C++ for plugins you’ll need to find a more open implementation of the language.
Cheers

On the flipside you get the .NET ecosystem integrated into your Python…

1 Like

There are initiatives (1, 2) that target running CPython in Rhino/Grasshopper, which enables one to implement numpy/scipy. I haven’t really messed with either one, but there certainly are considerable dependencies and plumbing involved, making it less than straightforward. An alternative (and arguably simpler) approach is to implement an equivalent .NET library (in this case, for instance Math.NET).

This is a new announcement, an interesting Python component that may work for this: