Python modules (NumPy) in Bonsai

770 views
Skip to first unread message

Johannes Larsch

unread,
Apr 20, 2015, 4:34:58 AM4/20/15
to bonsai...@googlegroups.com
Hi,

can you provide more detail on how to access python modules in Bonsai - specifically NumPy?
It appears IronPython doesn't support NumPy but your post on PointGray timestamps suggests that you have it working?
I may be missing something basic - how do I install Python modules for Bonsai to find them?

http://ironpython.codeplex.com/wikipage?title=FAQ  (under compatibility)


Johannes

goncaloclopes

unread,
Apr 20, 2015, 8:10:22 PM4/20/15
to bonsai...@googlegroups.com
Hi Johannes,

As it turns out, it WAS possible to run NumPy on IronPython/Bonsai in the past using the port done for the Python Tools project:

Basically the problem is that NumPy/SciPy is not pure python, it depends on the native integration layer which is different between Python and IronPython... However if you rebuild the native layer it is actually fine!

Unfortunately, since last year the project seems to have been taken offline and I can't get a hold of the binaries anymore. It was really simple, basically you just needed to copy a specially built version of NumPy/SciPy to the IronPython install and that was it. I'll let you know if I can recover the files.

Generally, to import arbitrary Python modules outside of the basic libraries you need to add them to the Sys path in the script itself. This will most likely be made easier in the future, but for now it would be something like this (for NumPy):

import sys
sys
.path.append('C:\\Program Files (x86)\\IronPython 2.7\\Lib')
sys
.path.append('C:\\Program Files (x86)\\IronPython 2.7\\DLLs')
sys
.path.append('C:\\Program Files (x86)\\IronPython 2.7')
sys
.path.append('C:\\Program Files (x86)\\IronPython 2.7\\lib\\site-packages')

import clr
clr
.AddReference('mtrand.dll')

import numpy


Convoluted I know, but definitely possible. Now if I can just find those DLLs it would be golden.

By the way, if anything else from the forums is listening in and has a copy of these DLLs I would love to hear from you!

Best,
Gonçalo

Johannes Larsch

unread,
Dec 5, 2016, 5:21:19 PM12/5/16
to Bonsai Users
hi goncalo,
did you figure out how to install numpy? I found your stackoverflow post I think. After downloading the package from enthough and installing ironpython, I am now stuck with the bootstrapper.
ironpkg bootstrapped fine but ironpkg scipy causes lots of errors.

Gonçalo Lopes

unread,
Dec 5, 2016, 5:31:16 PM12/5/16
to Johannes Larsch, Bonsai Users
Hi Johannes,

Is this a new package from enthought, or is it the old DLLs still?
I still can't find them anywhere.

I have a vague memory that scipy had some issues as well, so this may well be how far I got in the past also...


--
You received this message because you are subscribed to the Google Groups "Bonsai Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bonsai-users+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/bonsai-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/bonsai-users/74cd4261-c017-4a79-b37a-4b648a670d2c%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Johannes Larsch

unread,
Dec 5, 2016, 5:58:00 PM12/5/16
to Bonsai Users, johanne...@gmail.com
so this link has a protocol how to bootstrap the 'eggs'. I did this and got a folder with a bunch of DLLs which included mtrand.dll. (in following the protocol, I downgraded to ironpython 2.7. Bonsai complained so I upgraded again, this time to 2.7.6.3)
Now I followed your instructions above to add the new ironpython folders to the path and import numpy but Bonsai is not happy: "could not add reference to assembly mtrand.dll"
Is there a way forward from here?

Johannes Larsch

unread,
Dec 5, 2016, 5:58:46 PM12/5/16
to Bonsai Users, johanne...@gmail.com

Johannes Larsch

unread,
Dec 5, 2016, 6:36:45 PM12/5/16
to Bonsai Users, johanne...@gmail.com
its strange: in bonsai 32bit, I can get as far as importing numpy and it generates output in the win command bonsai output console (in this code example, printing the path, numpy version and np.pi

but running a workflow containing this python node complains about system.insufficientMemory no matter how tiny the program...

import clr
import sys
sys.path.append(r'c:\Program Files (x86)\IronPython 2.7')
sys.path.append(r'c:\Program Files (x86)\IronPython 2.7\DLLs')
sys.path.append(r'c:\Program Files (x86)\IronPython 2.7\Lib')
sys.path.append(r'c:\Program Files (x86)\IronPython 2.7\Lib\site-packages')
print sys.path

import clr
clr.AddReference('mtrand.dll')

import numpy as np
print np.__version__

print np.pi


@returns(int)
def process(input):
  a=1

  return a
Reply all
Reply to author
Forward
0 new messages