python3.6:安装 QuantLib 和 QuantLib-SWIG 后没有名为 _QuantLib 的模块

python 3.6: No module named _QuantLib after installation of QuantLib and QuantLib-SWIG

我正在尝试在 Mac OSX 10.12.5 Sierra 和 Python 3.6.1. 上安装 QuantLib 和 Python QuantLib-SWIG,但收到错误消息:

ImportError: dlopen(build/lib.macosx-10.7-x86_64-
3.6/QuantLib/_QuantLib.cpython-36m-darwin.so, 2): Symbol not found: __ 
ZN8QuantLib10DateParser14parseFormattedERKSsS2_
Referenced from: build/lib.macosx-10.7-x86_64-
3.6/QuantLib/_QuantLib.cpython-36m-darwin.so
Expected in: flat namespace
in build/lib.macosx-10.7-x86_64-3.6/QuantLib/_QuantLib.cpython-36m-darwin.so

以及:

ModuleNotFoundError: No module named '_QuantLib'

Luigi 在这个线程中对 QuantLib 用户的 mailing list 提出了一个非常有用的建议,我实施并取得了一些进展,但我仍然无法完成 Python 3.6 的安装。

我已经能够为 Python 2.

成功构建 QuantLib

我还尝试使用下面的动态加载构建 QuantLib(即我 rm'ed /usr/local/lib/libQuantLib* 然后在下面的第 5 步中不使用 '--disable-shared --enable-static' 重新运行该过程,但这也失败了.... :(.)

有人有什么建议吗?提前谢谢你。

错误日志

~/QuantLib-SWIG-1.10/Python>  /Users/tf/anaconda/bin/python3.6 setup.py 
install 
running install
running build
running build_py
running build_ext
running install_lib
creating /Users/tf/anaconda/lib/python3.6/site-packages/QuantLib
copying build/lib.macosx-10.7-x86_64-3.6/QuantLib/__init__.py -> /Users/tf/anaconda/lib/python3.6/site-packages/QuantLib
copying build/lib.macosx-10.7-x86_64-3.6/QuantLib/_QuantLib.cpython-36m-darwin.so -> /Users/tf/anaconda/lib/python3.6/site-packages/QuantLib
copying build/lib.macosx-10.7-x86_64-3.6/QuantLib/QuantLib.py -> /Users/tf/anaconda/lib/python3.6/site-packages/QuantLib
byte-compiling /Users/tf/anaconda/lib/python3.6/site-packages/QuantLib/__init__.py to __init__.cpython-36.pyc
byte-compiling /Users/tf/anaconda/lib/python3.6/site-packages/QuantLib/QuantLib.py to QuantLib.cpython-36.pyc
running install_egg_info
Writing /Users/tf/anaconda/lib/python3.6/site-packages/QuantLib_Python-1.10-py3.6.egg-info
~/QuantLib-SWIG-1.10/Python> /Users/tf/anaconda/bin/python3.6 setup.py test
running test
running build
running build_py
running build_ext
Traceback (most recent call last):
  File "build/lib.macosx-10.7-x86_64-3.6/QuantLib/QuantLib.py", line 18, in swig_import_helper
    return importlib.import_module(mname)
  File "/Users/tf/anaconda/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 648, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 560, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 922, in create_module
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
ImportError: dlopen(build/lib.macosx-10.7-x86_64-3.6/QuantLib/_QuantLib.cpython-36m-darwin.so, 2): Symbol not found: __ZN8QuantLib10DateParser14parseFormattedERKSsS2_
  Referenced from: build/lib.macosx-10.7-x86_64-3.6/QuantLib/_QuantLib.cpython-36m-darwin.so
  Expected in: flat namespace
 in build/lib.macosx-10.7-x86_64-3.6/QuantLib/_QuantLib.cpython-36m-darwin.so

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "setup.py", line 252, in <module>
    'build_ext': my_build_ext
  File "/Users/tf/anaconda/lib/python3.6/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/Users/tf/anaconda/lib/python3.6/distutils/dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "/Users/tf/anaconda/lib/python3.6/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "setup.py", line 58, in run
    module = __import__('QuantLibTestSuite', globals(), locals(), [''])
  File "test/QuantLibTestSuite.py", line 22, in <module>
    from date import DateTest
  File "test/date.py", line 18, in <module>
    import QuantLib
  File "build/lib.macosx-10.7-x86_64-3.6/QuantLib/__init__.py", line 21, in <module>
    from .QuantLib import *
  File "build/lib.macosx-10.7-x86_64-3.6/QuantLib/QuantLib.py", line 21, in <module>
    _QuantLib = swig_import_helper()
  File "build/lib.macosx-10.7-x86_64-3.6/QuantLib/QuantLib.py", line 20, in swig_import_helper
    return importlib.import_module('_QuantLib')
  File "/Users/tf/anaconda/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_QuantLib'

我是如何尝试安装 QuantLib

  1. 安装:

    • Xcode 8.3.3
    • Apple 的命令行开发人员工具,通过 运行 在终端上:xcode-select --install
    • 酿造
    • boost,通过 运行 在终端上:brew install boost
  2. 从 sourceforge 下载 tars:

    • 量化库 1.10
    • QuantLib-SWIG 1.10
  3. 将以上内容解压到主目录: /Users/tf/

  4. 在终端上通过 运行 切换到 QuantLib-1.10: cd ~/QuantLib-1.10

  5. 运行 在终端上: #./configure --with-boost-include=/usr/local/include/ --with-boost-lib=/usr/local/lib/ --prefix=/usr/local/ CXXFLAGS='-O2 -stdlib= libc++ -mmacosx-version-min=10.9' LDFLAGS='-stdlib=libc++ -mmacosx-version-min=10.9' --disable-shared --enable-static

  6. 运行 在终端上: make && sudo make install

  7. 通过 运行 在终端上测试 C++ 安装: cd Examples/BermudanSwaption && g++ -I/usr/local/include/ -I/usr/local/include/boost BermudanSwaption.cpp -o bermudanswaption -L/usr/local/lib/ -lQuantLib

  8. 在终端上通过 运行 切换到 QuantLib-SWIG-1.10: cd ~/QuantLib-SWIG-1.10 运行 在终端上: ./configure CXXFLAGS='-O2 -stdlib=libc++ -mmacosx-version-min=10.9' LDFLAGS='-stdlib=libc++ -mmacosx-version-min=10.9'

  9. 通过 运行 在终端上制作 C++ Python 版本: cd Python && /Users/tf/anaconda/bin/python3.6 setup.py build

  10. 在终端上通过 运行 安装到 anaconda: /Users/tf/anaconda/bin/python3.6 setup.py 安装

  11. 在终端上通过 运行 检查: /Users/tf/anaconda/bin/python3.6 setup.py 测试

我如何在 Luigi 的帮助下成功安装 QuantLib-SWIG

  1. 安装:

    • Xcode 8.3.3
    • Apple 的命令行开发人员工具,通过 运行 在终端上:xcode-select --install
    • 酿造
    • 提升,通过 运行 在终端上:brew install boost
  2. 从 sourceforge 下载 tars:

    • 量化库 1.10
    • QuantLib-SWIG 1.10
  3. 解压以上内容到主目录:/Users/tf/

  4. 在终端上通过 运行 切换到 QuantLib-1.10:cd ~/QuantLib-1.10

  5. 运行 在终端上:./configure --with-boost-include=/usr/local/include/ --with-boost-lib=/usr/local/lib/ --prefix=/usr/local/ CXXFLAGS='-O2 -stdlib=libc++ -mmacosx-version-min=10.9' LDFLAGS='-stdlib=libc++ -mmacosx-version-min=10.9' --disable-shared --enable-static

  6. 运行 在终端上:make && sudo make install

  7. 通过 运行 在终端上测试 C++ 安装:cd Examples/BermudanSwaption && g++ -I/usr/local/include/ -I/usr/local/include/boost BermudanSwaption.cpp -o bermudanswaption -L/usr/local/lib/ -lQuantLib

  8. 在终端上通过 运行 切换到 QuantLib-SWIG-1.10:cd ~/QuantLib-SWIG-1.10 运行 在终端上:./configure CXXFLAGS='-O2 -stdlib=libc++ -mmacosx-version-min=10.9' LDFLAGS='-stdlib=libc++ -mmacosx-version-min=10.9'

  9. 通过 运行 在终端上制作 C++ Python 版本:cd Python && export CXXFLAGS='-O2 -stdlib=libc++ -mmacosx-version-min=10.9' && export LDFLAGS='-stdlib=libc++ -mmacosx-version-min=10.9' && /Users/tf/anaconda/bin/python3.6 setup.py build

  10. 在终端上通过 运行 安装到 anaconda:/Users/tf/anaconda/bin/python3.6 setup.py install

  11. 在终端上通过 运行 检查:/Users/tf/anaconda/bin/python3.6 setup.py test