Need help by using an external python module in Blender-bounded Python

Hi,

first of all, I want to say that I am new to Blender and Python. My aim is to read data from the Wii Balance Board and map the data to a character in Blender. For this I downloaded the modul WiiYourself (http://wiiyourself.gl.tter.org/) which provides a python wrapper.
I installed the library for my normal python environment in C:\Python32. This installation was successful and by using my python script I can read data from the Wii Balance Board.

But now I have a big problem to integrate the module into Blender Python, so that I can read the data from the Balance Board from Blender. My first try was that I just add the path ‘C:\Python32\Lib\site-packages’ to the sys.path of the Blender-bounded python. But Blender Python tells me that this module can not be loaded.

Any further ideas how I can add my module to Blender or any tutorials or links ?
Thank you very much!

Edit:

  • I want to tell that I also use Python 3.2 in my local environment like my Blender 2.59
  • I use Windows 7

(I need) a littlebit more info
You did something like this:
import sys
sys.path.apend(‘C:\Python32\Lib\site-packages’)

And then?
And what error messages, exactly?

I did this in Bl 2.60


import sys
sys.path.append("C:/Python32/Lib/site-packages")
import numpy
print(dir(numpy))

and got (excerpt)

‘abs’, ‘absolute’, ‘add’, ‘add_docstring’, ‘add_newdoc’, ‘add_newdocs’, ‘alen’, ‘all’, ‘allclose’, ‘alltrue’, ‘alterdot’, ‘amax’, ‘amin’, ‘angle’, ‘any’, ‘append’, ‘apply_along_axis’, ‘apply_over_axes’, ‘arange’, ‘arccos’, ‘arccosh’, ‘arcsin’, ‘arcsinh’, ‘arctan’, ‘arctan2’, ‘arctanh’, ‘argmax’, ‘argmin’, ‘argsort’, ‘argwhere’, ‘around’, ‘array’, ‘array2string’, ‘array_equal’, ‘array_equiv’, ‘array_repr’, ‘array_split’, ‘array_str’, ‘asanyarray’, ‘asarray’, ‘asarray_chkfinite’, ‘ascontiguousarray’, ‘asfarray’, ‘asfortranarray’, ‘asmatrix’, ‘asscalar’, ‘atleast_1d’, ‘atleast_2d’, ‘atleast_3d’, ‘average’, ‘bartlett’, ‘base_repr’, ‘bench’, ‘binary_repr’, ‘bincount’, ‘bitwise_and’, ‘bitwise_not’, ‘bitwise_or’, ‘bitwise_xor’, ‘blackman’, ‘bmat’, ‘bool’, ‘bool8’, ‘bool_’, ‘broadcast’, ‘broadcast_arrays’, ‘byte’, ‘byte_bounds’, ‘bytes0’, ‘bytes_’, ‘c_’, ‘can_cast’, ‘cast’, ‘cdouble’, ‘ceil’, ‘cfloat’, ‘char’, 'characte

EDIT,
Blender 2.59 and up use automatically Python 3.2 (not official but my 2.59.4 and 2.60 do!)

Ok sorry …

Here are the further steps:

After I add C:\Python32\Lib\site-packages where the wiimote module is located to the sys.path of the Blender-bounded python environment, I executed the command “import wiimote”. Here is the corresponding output:


>>> import wiimote
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
  File "C:\Python32\lib\site-packages\wiimote.py", line 26, in <module>
    _wiimote = swig_import_helper()
  File "C:\Python32\lib\site-packages\wiimote.py", line 22, in swig_import_helper
    _mod = imp.load_module('_wiimote', fp, pathname, description)
ImportError: DLL load failed: %1 no valid Win32-Application.

If I am right, this tells me that the module was found, but can not load the dynamic library. In the folder ‘C:\Python32\Lib\site-packages’ the following files are located:

  • wiimote.py
  • _wiimote.pyd
  • wiimote.pyc
  • wiimote-1.15RC2-py3.2.egg-info

I hope this helps a little bit. If you need further information, please let me know

OK, that is much more clear but I am at the end of my knowledge …only chance is, taht hou look into wiimote.py and there the swig_import_helper
It looks like that you need to have the DLL where the ‘helper’ looks for …

Ok i modify the swig_import_helper() a little bit by adding some information output:

Here is the method:


def swig_import_helper():
        from os.path import dirname
        import imp
        fp = None
        try:
            print("file=",__file__)            
            fp, pathname, description = imp.find_module('_wiimote', [dirname(__file__)])
            print("pathname=",pathname)
            print("fp=",fp)
            print("description=",description)
        except ImportError:
            import _wiimote
            return _wiimote
        if fp is not None:
            try:                    
                _mod = imp.load_module('_wiimote', fp, pathname, description)
            finally:
                fp.close()
            return _mod

And here is the output:


>>> import wiimote
file= C:\Python32\lib\site-packages\wiimote.py
pathname= C:\Python32\lib\site-packages\_wiimote.pyd
fp= <_io.BufferedReader name=5>
description= ('.pyd', 'rb', 3)

Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
  File "C:\Python32\lib\site-packages\wiimote.py", line 30, in <module>
    _wiimote = swig_import_helper()
  File "C:\Python32\lib\site-packages\wiimote.py", line 26, in swig_import_helper
    _mod = imp.load_module('_wiimote', fp, pathname, description)
ImportError: DLL load failed: Module not found.

I really don’t know why it doesn’t work …

I think you have to believe the error message.
Try to find out WHICH DLL is needed and not found and check if you really have it…

eventually, a ctypes (from your Blender) … calling kernel32 is not made for importing ???
If so, ask for a version where it is available …

From hearsay, one can have a Blender NOT with the internal Python 3.2 but with a REAL Python 3.2 instead and if
your Python 32. can import the wii things, (if I am at all correct) Blender must informed about YOUR Python 3.2

Hi,
I am trying exactly the same and get:

>>> sys.path.append(’----/local/lib/python3.2/site-packages’)
>>> import numpy
Traceback (most recent call last):
File “<blender_console>”, line 1, in <module>
File “----/local/lib/python3.2/site-packages/numpy/init.py”, line 137, in <module>
from . import add_newdocs
File “----/local/lib/python3.2/site-packages/numpy/add_newdocs.py”, line 9, in <module>
from numpy.lib import add_newdoc
File “----/local/lib/python3.2/site-packages/numpy/lib/init.py”, line 4, in <module>
from .type_check import *
File “----/local/lib/python3.2/site-packages/numpy/lib/type_check.py”, line 8, in <module>
import numpy.core.numeric as _nx
File “----/local/lib/python3.2/site-packages/numpy/core/init.py”, line 5, in <module>
from . import multiarray
ImportError: cannot import name multiarray

I use the bundled python and blender 2.6 64bit from the website. I build numpy myself with python3.2.2. On a different computer I have root access and compiled blender myself using the system python3.2.2, which then works perfectly with numpy. Is it possible to compile numpy with the bundled blender python directly? Or is it possible to get blender2.6 to use my system python and not the bundled one without recompiling? Why can’t it import multiarray? It is in the numpy directory which is obviously found…

Any ideas? Thank’s for help!

oh I forgot: numpy 1.6.1

you are trying to use 32 bit on 64 bit platform or 64 bit on 32 bit?
that would explain the missing .dlls

yes i am trying to use blender32 bit with python3.2 32bit on a 64bit system. you think that is the problem ?
I think this should not be the error because on my standalone 32bit python32 environment at c:\Python32 it works fine …