本文介绍了python 3.6:安装QuantLib和QuantLib-SWIG后,没有名为_QuantLib的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to install QuantLib and Python QuantLib-SWIG on Mac OSX 10.12.5 Sierra and Python 3.6.1., but get error messages:

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用户的邮件列表中对此线程给出了非常有用的建议,我实现并取得了一些进展,但仍然无法完成Python 3.6的安装.

Luigi gave a very useful suggestion in this thread on the QuantLib users' mailing list, which I implemented and made some progress, but I still cannot finish installation for Python 3.6.

我已经能够成功构建适用于Python 2的QuantLib.

I have been able to successfully build QuantLib for Python 2.

我还尝试使用下面的动态加载来构建QuantLib(即我rm/usr/local/lib/libQuantLib *,然后在步骤#5中重新运行过程,而没有使用"--disable-shared --enable-static"下面,但是也失败了....:(.)

I also tried to build QuantLib with dynamic loading below (i.e. I rm'ed /usr/local/lib/libQuantLib* and then reran the process without '--disable-shared --enable-static' in step #5 below, but that also failed.... :(.)

有人有什么建议吗?预先谢谢你.

Anyone have any advice? Thank you in advance.

~/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. 安装:

  1. Install:

  • Xcode 8.3.3
  • Apple的命令行开发人员工具,通过在以下终端上运行:xcode-select --install
  • 酿造
  • 增强功能,通过在终端上运行:brew install boost

从sourceforge下载tar:

Download the tars from sourceforge:

  • QuantLib 1.10
  • QuantLib-SWIG 1.10

将以上内容提取到主目录: /Users/tf/

Extract the above to home directory: /Users/tf/

通过在终端上运行,切换到QuantLib-1.10: cd〜/QuantLib-1.10

Switch to QuantLib-1.10 by running on terminal: cd ~/QuantLib-1.10

在终端上运行: #./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

Run on terminal: #./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

在终端上运行: 制作&& sudo make install

Run on terminal: make && sudo make install

通过在终端上运行来测试C ++的安装: cd示例/百慕大交换&& g ++ -I/usr/local/include/-I/usr/local/include/boost BermudanSwaption.cpp -o bermudanswaption -L/usr/local/lib/-lQuantLib

Test C++ installation by running on terminal: cd Examples/BermudanSwaption && g++ -I/usr/local/include/ -I/usr/local/include/boost BermudanSwaption.cpp -o bermudanswaption -L/usr/local/lib/ -lQuantLib

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

Switch to QuantLib-SWIG-1.10 by running on terminal: cd ~/QuantLib-SWIG-1.10Run on terminal: ./configure CXXFLAGS='-O2 -stdlib=libc++ -mmacosx-version-min=10.9' LDFLAGS='-stdlib=libc++ -mmacosx-version-min=10.9'

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

Make the C++ Python version by running on terminal: cd Python && /Users/tf/anaconda/bin/python3.6 setup.py build

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

Install to anaconda by running on terminal: /Users/tf/anaconda/bin/python3.6 setup.py install

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

Check by running on terminal: /Users/tf/anaconda/bin/python3.6 setup.py test

推荐答案

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

  1. 安装:

  1. Install:

  • Xcode 8.3.3
  • Apple的命令行开发工具,通过在以下终端上运行:xcode-select --install
  • 酿造
  • 通过在终端brew install boost
  • 上运行来增强
  • Xcode 8.3.3
  • Apple’s Command Line Developer Tools, by running on terminal: xcode-select --install
  • brew
  • boost, by running on terminal: brew install boost

从sourceforge下载tar:

Download the tars from sourceforge:

  • QuantLib 1.10
  • QuantLib-SWIG 1.10

将以上内容提取到主目录:/Users/tf/

Extract the above to home directory: /Users/tf/

通过在终端cd ~/QuantLib-1.10

在终端上运行:./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

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

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

Test C++ installation by running on terminal: cd Examples/BermudanSwaption && g++ -I/usr/local/include/ -I/usr/local/include/boost BermudanSwaption.cpp -o bermudanswaption -L/usr/local/lib/ -lQuantLib

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

Switch to QuantLib-SWIG-1.10 by running on terminal: cd ~/QuantLib-SWIG-1.10Run on terminal: ./configure CXXFLAGS='-O2 -stdlib=libc++ -mmacosx-version-min=10.9' LDFLAGS='-stdlib=libc++ -mmacosx-version-min=10.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

Make the C++ Python version by running on terminal: 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

通过在终端/Users/tf/anaconda/bin/python3.6 setup.py install

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

Check by running on terminal: /Users/tf/anaconda/bin/python3.6 setup.py test

这篇关于python 3.6:安装QuantLib和QuantLib-SWIG后,没有名为_QuantLib的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 19:29