QuantLib-Python 无法检测 QuantLib 安装和致命错误 C1083

QuantLib-Python unable to detect QuantLib installation and fatal error C1083

我已经安装了 QuantLib 和 boost(我猜对了)。所有示例在 C/C++ 到 visual studio 2017 中都可以正常工作。

现在我想安装 QuantLib-Python 版本。我有一个类似于

的问题

Python binding through QuantLib-SWIG

然而,我在设置环境变量时删除了=符号周围的空格。 (我还通过“我的电脑”->“属性”->“高级系统设置”->“环境变量”向环境变量添加了该路径)但是 QuantLib python 的构建一直无法正常工作。我得到以下输出

(base) C:\opt-libs\QuantLib-SWIG-1.13\Python>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 Studio17\Community\VC\Tools\MSVC.14.26428\bin\HostX86\x86\cl.exe/c/nologo /Ox /W3 /GL /DNDEBUG /MD -D__WIN32__ -DWIN32 -DNDEBUG -D_WINDOWS -DNOMINMAX "-IC:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_86\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_86\include" -IC:\opt-libs\boost_1_67_0 "-IC:\Program Files (x86)\Microsoft Visual Studio17\Community\VC\Tools\MSVC.14.26428\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio17\Community\VC\Tools\MSVC.14.26428\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\include.0.17134.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\include.0.17134.0\shared" "-IC:\Program Files (x86)\Windows Kits\include.0.17134.0\um" "-IC:\Program Files (x86)\Windows Kits\include.0.17134.0\winrt" "-IC:\Program Files (x86)\Windows Kits\include.0.17134.0\cppwinrt" -IC:\opt-libs\boost_1_67_0 /EHsc /TpQuantLib/quantlib_wrap.cpp /Fobuild\temp.win32-3.6\Release\QuantLib/quantlib_wrap.obj /GR /FD /Zm250 /EHsc /bigobj /MD quantlib_wrap.cpp
QuantLib/quantlib_wrap.cpp(4000): fatal error C1083: Cannot open include file: 'ql/version.hpp': No such file or directory
error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\bin\HostX86\x86\cl.exe' failed with exit status 2

编辑更新

感谢 Luigi Ballabio 的友善回答,我正确地设置了 QL_DIR。现在我得到的错误信息如下

(base) C:\opt-libs\QuantLib-SWIG-1.13\Python>python setup.py build
running build
running build_py
running build_ext
building 'QuantLib._QuantLib' extension
C:\Program Files (x86)\Microsoft Visual Studio17\Community\VC\Tools\MSVC.14.26428\bin\HostX86\x86\cl.exe /c/nologo /Ox /W3 /GL /DNDEBUG /MD -D__WIN32__ -DWIN32 -DNDEBUG -D_WINDOWS -DNOMINMAX "-IC:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_86\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_86\include" -IC:\opt-libs\QuantLib-1.13;C:\opt-libs\QuantLib-1.13\lib;C:\opt-libs\QuantLib-1.13\ql -IC:\opt-libs\boost_1_67_0 "-IC:\Program Files (x86)\Microsoft Visual Studio17\Community\VC\Tools\MSVC.14.26428\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio17\Community\VC\Tools\MSVC.14.26428\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\include.0.17134.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\include.0.17134.0\shared" "-IC:\Program Files (x86)\Windows Kits\include.0.17134.0\um" "-IC:\Program Files (x86)\Windows Kits\include.0.17134.0\winrt" "-IC:\Program Files (x86)\Windows Kits\include.0.17134.0\cppwinrt" -IC:\opt-libs\boost_1_67_0 /EHsc /TpQuantLib/quantlib_wrap.cpp /Fobuild\temp.win32-3.6\Release\QuantLib/quantlib_wrap.obj /GR /FD /Zm250 /EHsc /bigobj /MD quantlib_wrap.cpp
QuantLib/quantlib_wrap.cpp(4000): fatal error C1083: Cannot open include file: 'ql/version.hpp': No such file or directory
error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\bin\HostX86\x86\cl.exe' failed with exit status 2 

警告 "unable to detect QuantLib installation" 表示安装脚本无法读取 QL_DIR 环境变量。正如您链接的问题一样,您应该将其设置为您的 QuantLib 文件夹的路径。设置后,您可能必须重新启动用于构建包装器的命令提示符。

(也就是说,在构建包装器之前,请尝试 运行

pip install QuantLib-Python

根据您的 Python 版本,您有可能获得预编译的二进制文件。)

更新:设置QL_DIR后,我发现您仍然遇到错误"Cannot open include file: 'ql/version.hpp'"。这表明包含目录设置不正确,实际上您的命令行包含一个无法工作的开关 -IC:\opt-libs\QuantLib-1.13;C:\opt-libs\QuantLib-1.13\lib;C:\opt-libs\QuantLib-1.13\ql,因为 -I 不采用路径列表;根据您的 QL_DIR,它应该是 -IC:\opt-libs\QuantLib-1.13,我想是 C:\opt-libs\QuantLib-1.13——我说得对吗?

简而言之,我会检查从命令提示符中看到的 QL_DIR 的值;你可以用

显示它
echo %QL_DIR%

如果它是路径列表,请将其重置为指向 QuantLib 目录的单个路径。