Importing external modules for scripting


#1

Hey all,

I’m trying to use the numpy module in some scripts and I can’t figure out how to import it. I have Python3.3 installed in the normal C:\Python33\ directory and numpy is installed in C:\Python33\Lib\site-packages by default; I tried adding the C:\Python33\Lib\ directory to my search path in the python editor (because the Iron Python libs seem to have the ‘same’ search path) and when i print sys.path I get:

[‘C:\Temp’, ‘C:\Program Files\Rhinoceros 5.0 (64-bit)\Plug-ins\IronPython\Lib’, ‘C:\Users\bertram\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib’, ‘C:\Users\bertram\AppData\Roaming\McNeel\Rhinoceros\5.0\scripts’, ‘C:\Python33\Lib’]

so it’s clearly acknowledging that I’m trying to do this.

I should add that I’m getting the “no module named numpy” message from the interpreter when I import numpy

If anyone could give me a bit of an overview regarding importing 3rd party modules it would be much appreciated.


NumPy (or other external lib) on OSX?
(Steve Baer) #2

I haven’t touched this subject for a long time, but I wrote about using numpy a while ago. It may help


#3

Thanks, Steve. Got it working fine!


#4

Hi DefterGoose and Steve,

I’m currently looking to get started with Numpy/Scipy. It seems that this thread is the latest successful example of someone getting Numpy running in RhinoPython that I could find. I have tried following the steps provided here and keep getting stuck on step number three. Specifically the “bootstrap” bit. I have tried Goggling this without much luck.

Would you mind elaborating how you got it working? Also, did you manage to run it on 64 bit Rhino?

Best and thanks,

Anders


#5

It turns out that the security settings on my Ironpython folder were set too high:

After fiddling with that for a while I managed to install ironpkg, Numpy and Scipy as per the instructions provided by Enthought. Afterwards I added the paths to the Numpy/Scipy folders in the “EditPythonScript” editor and enabled frames. However when I now attempt to import Numpy like so:

import clr
clr.AddReference("mtrand")
 
import numpy

I get:

Runtime error (IOException): Could not add reference to assembly mtrand

I assume that this has to do with my Rhino being 64 bit and the dll dependencies being 32 bit? In which case perhaps it would be possible to use the unofficial 64 bit binaries found here instead?

Any ideas?

Thanks,

Anders


(Steve Baer) #6

I’m pretty confident this has to do with running 64bit Rhino and I have little hope that the unofficial binaries link you posted will help. I contacted enthought a while ago and they are using managed C++ to deliver their 32bit versions of numpy specifically for ironpython.


#7

Thanks for the reply Steve,

That’s unfortunate. We were hoping to implement Numpy/Scipy in a research project looking at AI, machine learning, clustering etc. It seems that many Python libraries within this field rely on Numpy for fast and efficient arrays and Scipy for additional functionality. I don’t suppose that Enthought were planning a 64 bit release for ironpython?

Either way, I would still be interested in testing out the libraries using a 32 bit version of Rhino. Would you happen to know if this version comes with the current Rhino 5 installer?

Thanks again,

Anders


(Steve Baer) #8

Yes, the V5 installer should contain both 32 and 64


#9

Excellent, thanks Steve…