Author Topic: import problem, QuantLib SWIG python bindings  (Read 4970 times)

bondgeek

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
import problem, QuantLib SWIG python bindings
« on: January 03, 2011, 04:43:47 AM »
I am trying to create a PyXLL UDF that uses the Python bindings for QuantLib, which are created using SWIG.

The QuantLib module works fine in a regular call from Python:
Code: [Select]
>>> from QuantLib import Date as qlDate
>>> ql.Date.todaysDate().ISO()
'2011-01-02'
>>>

Here is the python code (in a file called 'qlTest.py') and the errors in PyXLL's log file:
Code: [Select]
from pyxll import xl_func

from QuantLib import Date as qlDate

@xl_func("string name: string")
def qlToday(str=None):
    """return ISO string of quantlib date"""
   
    return qlDate.todaysDate().ISO()

Code: [Select]
INFO : PyXLL Addin pyxll started
ERROR : Error importing 'qlTest': DLL load failed: The specified module could not be found.
ERROR : Traceback (most recent call last):
ERROR :   File "pyxll", line 402, in _open
ERROR :   File "C:\Users\Public\Libraries\pyxll\qlTest.py", line 3, in <module>
ERROR :     from QuantLib import Date as qlDate
ERROR :   File "C:\Python26\Lib\site-packages\QuantLib\__init__.py", line 19, in <module>
ERROR :     from QuantLib import *
ERROR :   File "C:\Python26\Lib\site-packages\QuantLib\QuantLib.py", line 24, in <module>
ERROR :     _QuantLib = swig_import_helper()
ERROR :   File "C:\Python26\Lib\site-packages\QuantLib\QuantLib.py", line 20, in swig_import_helper
ERROR :     _mod = imp.load_module('_QuantLib', fp, pathname, description)
ERROR : ImportError: DLL load failed: The specified module could not be found.

Is there something that needs to be done to allow PyXLL to find the module?

Thanks.

Tony

  • Administrator
  • Hero Member
  • *****
  • Posts: 574
  • Karma: +13/-1
    • View Profile
Re: import problem, QuantLib SWIG python bindings
« Reply #1 on: January 03, 2011, 12:45:03 PM »
Hi,

you need to ensure the module is in your pythonpath, either by setting it in the registry or as an environment variable, or in the pyxll config file.

You also need to make sure any dll dependencies are available in the system path (PATH environment variable).

You can check for any missing dependencies using depends.exe, which can be downloaded from http://www.dependencywalker.com.

Regards,
Tony

bondgeek

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: import problem, QuantLib SWIG python bindings
« Reply #2 on: January 04, 2011, 08:19:04 PM »
Thanks,  depends.exe helped identify MSVCP90.DLL & MSVCR90.DLL as the culprits. 

I think I've isolated the problem as arising from how disutils is compiling / linking the generating code to create _QuantLib.pyd.   So now I get to wade through the setup.py to figure it out, unless somebody else out there wants to volunteer.   :)