2
votes

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

as well as:

ModuleNotFoundError: No module named '_QuantLib'

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.

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

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.

Error log

~/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'

How I am trying to install QuantLib

  1. Install:

    • 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
  2. Download the tars from sourceforge:

    • QuantLib 1.10
    • QuantLib-SWIG 1.10
  3. Extract the above to home directory: /Users/tf/

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

  5. 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

  6. Run on terminal: make && sudo make install

  7. 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

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

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

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

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

1
Hi Taylor! Questions on Stack Overflow are only "closed" when there's something wrong with them. What you're thinking of is marking a question as "answered", which we do by clicking the hollow checkmark in the margin of an answer so it turns green. Only you (the original asker) can do that, and you can only do it on an answer. So what you should do is submit an answer to your own question, and mark it as the accepted answer as soon as the system allows you to do so. (Answers should never be edited into the question itself. We keep a clear separation here.)Cody Gray

1 Answers

2
votes

How I successfully installed QuantLib-SWIG, with Luigi's help

  1. Install:

    • 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
  2. Download the tars from sourceforge:

    • QuantLib 1.10
    • QuantLib-SWIG 1.10
  3. Extract the above to home directory: /Users/tf/

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

  5. 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

  6. Run on terminal: make && sudo make install

  7. 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

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

  9. 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

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

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