本文介绍了通过 QuantLib-SWIG 进行 Python 绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试让 QuantLib 的 Python 绑定工作一段时间,但到目前为止没有任何成功.

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

我确实遵循了 QuantLib 安装指南和 wiki.那就是使用 VC9 而不是 VC10 来构建 QuantLib,这对我来说很好用.

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

当我尝试构建 Python 安装文件时,我被告知 MSVC 无法检测到 QuantLib 安装.

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

请有人能告诉我我在这里遗漏了什么.正如您现在已经意识到的那样,我是一个初学者,如果过去曾反复问过问题,我深表歉意,但我在不同的论坛中找不到我的问题的任何答案:wilmott、sourceforge、stack溢出,量化交易.

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.

任何帮助将不胜感激.

最好的问候

这是日志:

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

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:\Python27\include -IC:\Python27\PC "-IC:\Program Files (x86)\Microsoft Visual Studio 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_wrap.obj/GR/FD/Zm250/EHsc/MDcl:命令行错误 D8003:缺少源文件名错误:命令 '"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\cl.exe"' 失败,退出状态为 2

/MD /W3 /GS- /DNDEBUG -D_WIN32_ -DWIN32 -DNDEBUG -D_WINDOWS -DNOMINMAX -IC:\Python27\include -IC:\Python27\PC "-IC:\Program Files (x86)\Microsoft Visual Studio 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_wrap.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.exe"' failed with exit status 2

推荐答案

设置环境变量的时候把 = 号周围的空格去掉,否则 Python 找不到.以下是我还在办公室的 WinXP 机器上发生的情况:

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(无空格设置)被找到;BAR(带)不是.

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

未找到 QL_DIR、INCLUDE 或 LIB 变量会导致其他级联错误.

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

这篇关于通过 QuantLib-SWIG 进行 Python 绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 19:32