win32com and numpy

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mauro b
    New Member
    • Jan 2011
    • 2

    win32com and numpy

    I am trying to use Excel as the front end for some python code.

    I get an error (below) when trying to use a python code including numpy. If I don't import numpy I do not get the error. Is win32 somehow incompatible with numpy? I would appreciate any information regarding this issue.


    Minimal example:

    Code:
    import win32com.server.register
    import pythoncom
    from numpy import mean
    
    class TimeSeriesManipulation:
        _public_methods_ = [ 'SplitString']
        _reg_progid_ = "PythonUtils.NumpyError"
        _reg_clsid_ = "{08A4D1F8-0185-4692-BE40-4AD081DB90B1}"
    
    
        def SplitString(self, val, item=None):
            from string import split
            if item != None: item = str(item)
            return split(str(val), item)
       
    if __name__=='__main__':
        print "Registering COM server..."
        import win32com.server.register
      win32com.server.register.UseCommandLine(TimeSeriesManipulation)
    Code:
    Sub tt()
    Set PythonUtils = CreateObject("PythonUtils.NumpyError")
    response = PythonUtils.SplitString("Hello from VB")
    For Each Item In response
    MsgBox Item
    Next
    End Sub
    I get a run-time error ' -21474677259(800 04005)':

    Unexpected Python Error: Traceback (most recent call last):
    File "C:\appl\python 26\lib\site-packages\win32c om\server\polic y.py",
    line 136 in CreateInstance
    return retObj._CreateI nstance_(clsid, reqIID)
    File "C:\appl\python 26\lib\site-packages\win32c om\server\polic y.py",
    line 194, in _CreateInstance _
    mvob = call func(classSpec)
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    line 194, in _CreateInstance _
    mvob = call func(classSpec)
    This line in not in the code you posted so it is difficult to tell. Note that the Numpy that you install has to match the Python version. So there are separate Numpy packages for Python2.5, 2.6, and 2.7.

    Comment

    • Mauro b
      New Member
      • Jan 2011
      • 2

      #3
      To clarify:
      Importing any function from numpy triggers an error when using the com object in excel. If I do not import anything from numpy, I do not get any errors.

      Comment

      Working...