Python binding through QuantLib-SWIG

假装没事ソ 提交于 2019-12-23 05:45:37

问题


I have been trying to get Python binding for QuantLib working for a while now but without any success so far.

I did follow QuantLib installation guidelines and wiki. That is to build QuantLib using VC9 and not VC10 which works fine for me.

When I try to build Python setup file, I am being told that MSVC cannot detect QuantLib installation.

Please could someone be kind enough to advise what I am missing here. As you would have realized by now, I am much of a beginner with this and apologize if question has been asked over and over in the past but I couldn't find any answer to my question in the different forums: wilmott, sourceforge, stack overflow,quant exchange.

Any help would be greatly appreciated.

Best regards

Here is the log:

c:\QuantLib\QuantLib-SWIG-1.2\Python>set INCLUDE = C:\boost\boost_1_51

c:\QuantLib\QuantLib-SWIG-1.2\Python>set QL_DIR = C:\QuantLib\QuantLib-1.2.1

c:\QuantLib\QuantLib-SWIG-1.2\Python>set LIB= C:\boost\boost_1_51\lib;C:\QuantLi

b\QuantLib-1.2.1\lib

c:\QuantLib\QuantLib-SWIG-1.2\Python>setup.py build
running build
running build_py
running build_ext
warning: unable to detect QuantLib installation
building 'QuantLib._QuantLib' extension
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c /nologo /Ox

/MD /W3 /GS- /DNDEBUG -D_WIN32_ -DWIN32 -DNDEBUG -D_WINDOWS -DNOMINMAX -IC:\Py thon27\include -IC:\Python27\PC "-IC:\Program Files (x86)\Microsoft Visual Studi o 9.0\VC\INCLUDE" "-IC:\Program Files\Microsoft SDKs\Windows\v6.0A\include" -I / TpQuantLib/quantlib_wrap.cpp /Fobuild\temp.win32-2.7\Release\QuantLib/quantlib_w rap.obj /GR /FD /Zm250 /EHsc /MD cl : Command line error D8003 : missing source filename error: command '"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\cl.ex e"' failed with exit status 2


回答1:


Remove the spaces around the = sign when you set the environment variables, or Python won't find them. Here is what happens on a WinXP box I still have around at the office:

C:\Documents and Settings\lballabio>set FOO=foo

C:\Documents and Settings\lballabio>set BAR = bar

C:\Documents and Settings\lballabio>python
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ['FOO']
'foo'
>>> os.environ['BAR']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\os.py", line 423, in __getitem__
    return self.data[key.upper()]
KeyError: 'BAR'
>>>

FOO (set without spaces) is found; BAR (with) is not.

Not finding the QL_DIR, INCLUDE or LIB variables causes the other errors in cascade.



来源:https://stackoverflow.com/questions/16902651/python-binding-through-quantlib-swig

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!