How to use numpy in VS code and Rhino

I install numpy. It can import but when press run the program is not work.

Hi @puree.srisuk64,

Rhino’s Python interpreter cannot use NumPy directly. Rhino uses IronPython, not CPython.

There are ways you can use NumPy with Rhino, however:

1.) Run Rhino inside of CPython.

2.) Use Grasshopper with the Hops component.

– Dale

Sorry, correct me if I’m wrong.
Let’s say I’m already using Iron Python and I have some working scripts, but I need to use some of the functions available in Numpy. What should I do…!?

  • use RhinoInside, but will I then be able to use the Eto framework, and to what extent is troubleshooting developed in this area, and how many examples are there for training? Plus I need to reconfigure the whole setup to work.
  • to use Grasshopper with the Hops and Flask … again the question is, can I then use the Eto framework in my scripts, and is Grasshopper optional, or is it a necessary intermediate link, without which this solution will not work?
    Actually in Numpy I only need a method to solve 3 and 4 degree polynomials. Is there an easy way to stay on the Iron Python? Maybe Rhino itself has built-in functions for finding the roots of a polynomial?
    I also ask respected experts to check the following link. As the description says:
    “ALGLIB - - numerical analysis library in C ++ and C #, with Python and IronPython interfaces.”
    Apparently this is a powerful library that can solve many necessary problems. But my knowledge is completely insufficient to understand whether it is possible to connect it to the OldSteelSnake or not.

Although the following statement is not entirely correct, IronPython is like writing C# code in Python 2 syntax. So you can use any library which has been written for C# as long as it is not targeting the newer the .Net Core. On top of that you can also use most C/C++ libraries, but accessing these is more complicated. So if Numpy is not there, just use a .Net library which does the same…

Besides this is not super complicated to implement a solver for equation systems(Gaußian solver, etc) or to solve zero crossings of polynomials (Newton method). In any case there are multiple .net libraries out for this sort mathematical computation.

The fact is that I am one of those light-hearted carefree people who have been coding in PyCharm for a couple of years. If I needed something specific, then all I had to do was find the name of the required module, write Import, press the red light in PyCharm … and voila. I mean… pip install…, what is that thing anyway!? Of course I’m kidding a little, but I mean – Numpy, CV2, TKinter, BeautifulSoup, Pillow and many other modules were just a click away from me. And I’m already used to how wonderful and simple everything is implemented in this environment. You say “not super complicated to implement a solver”.
And I need it like this:
poly = np.poly1d ([A, B, C, D, E])
roots = np.sort (poly.r) — that’s simple :)))
And I didn’t need to deeply understand the differences between one Python and another.
For example, I still cannot understand, when people here on the forum write “CPython”, is this the same “regular” Python that I’m used to, or is it something else? :))
I am interested in studying the essence of the Rhino, that is curves, surfaces, Meshes, to come up with some algorithms for working with these objects. And banging my forehead against a wall of deep technical nuances, especially after the Pycharm experience I wrote about above, is painful, I must say, and boring also.

1 Like

Give me an easy environment, I will move the whole savannah.

Don’t get me wrong here, I use PyCharm, CPython and Pip as well. The same experience you’ll get from VS and Nuget. But the reality is often that there is something missing or something doesn’t work as straight as expected. And then it helps to know how to circumvent certain issues. Dealing with CAD automation and geometry is in Rhino also carefree, but it doesn’t work well with your PyCharm experience. So you need to be flexible at some point. In general, there are two options. A.) you go for CPython and deal with all the hurdles within the Rhino environment, or B.) you find an alternative suited for Rhino, including implementing features by yourself.

Furthermore, calling library code is not the big deal of programming. If something is easy for you, it might only mean other people did the work. The more tailor-made solutions you are able to code, the more you move the whole savannah, not the other way around.

Okay, assuming you’re advising to an inexperienced nooby one, then what specific steps do I need to take on the CPython path?
I got version 3.8 from here Python Release Python 3.8.0 |
As I understood, no PyCharm, but will it work with VSC?
Then, apparently I need to install RhinoInside? Do I need to run the codeListener in Rhino itself?
And it turns out, if it will work, then in addition to NumPy, I will be able to use everything else, for example TKinter instead of Eto?
Or not?

FWIW in the future it is going to be easiest in Rhino 8 where you’ll have access to Pip directly in the new and improved Rhino code editor. See Rhino 8 Feature: RhinoCode (CPython, CSharp)

1 Like

Dale was pointing to this. I’m not a fan of using my preferred language in any context. I would always pick the right language for the right purpose. Clearly I would rather use a .net library in IronPython or C#, than using CPython just because of numpy or TK. (There are also .net bindings for TK I believe). But sure you can invoke any GUI framework. You only need to ship the correct libraries and have little-bit of experience of doing so.

Edit: Seems like CPython will fully replace IronPython in RH8…

According to which source? Officially speaking:

Okay, assuming you’re advising to an inexperienced nooby one, then what specific steps do I need to take on the CPython path? <

And after all, what should I do then?

If you have access to Rhino 8 WIP, and It’s ok to work on a dev version, then go for CPython and the new editor. It supports pip and numpy and tk
If you stick to Rhino 7 or older, or you need to make sure it’s a stable Rhino Release, or you want to support an older Rhino version, go for Iron-Python or C# and use numpy-alike library like "Math(.)Net "

In my opinion, this is the most straight-forward thing to do.

1 Like

I wrote it because we had a large user base using the legacy RhinoScript language and this was an easy way to transition away from RhinoScript and into python.

1 Like

Worked for me : Recoding legacy RhinoSycript code into rhinoscriptsyntax was a big part of my journey into python

It’s not dead, it’s pining for the fjords. :parrot:

I’m well aware of IronPython history, but declaring it “officially dead” is a false (or at least polemic) claim.

I’m not sure I ever stated anything to suggest otherwise.

Assuming it doesn’t mean significant loss of functionality and performance from IronPython (e.g. being able to easily/natively implement .NET, RhinoCommon, Grasshopper API), I don’t see why not. I do however worry that (as with all new technology), this likely won’t be the case. Which would negatively impact the creativity and productivity of myself and my team, as computational designers that work predominantly in GHPython (which, minor kinks and nit-picks aside, is a wonderful and mature platform at this point). So, instead of a hard switcheroo, I’d prefer natively providing both Pythons (ala how Dynamo is doing it), however “messy” this might feel. At least initially.

VB right :wink:

We are continuing to support IronPython in Rhino 8. People can choose which language they want to work in be it C#, VB, C++, or python. When it comes to python you will be able to choose which implementation you want to work with. There will probably be some bumps in the road as we start supporting cpython and we’ll fix things as we run into them.


Heres a bump: Numpy doesnt load!