python - 在 'apple silicon' Macbook 上运行 QuantLib python

标签 python apple-m1 quantlib

我正在尝试在具有 M1 处理器 (Big Sur v11.3) 的 Macbook 上运行 Quantlib-Python,遵循 https://www.quantlib.org/install/macosx-python.shtml 。我已经成功通过自制程序安装了 Quantlib 1.22 和 Python 3.9.4:

将 quantlib--1.22.arm64_big_sur.bottle.tar.gz 倒入“/opt/homebrew/Cellar/quantlib/1.22”

但是,当我尝试通过 pip 安装 Quantlib-Python 时,我得到:

错误:找不到满足 QuantLib 要求的版本(来自版本:无)
错误:找不到 QuantLib 的匹配发行版

由此看来,虽然 Quantlib 1.22 已经为基于 Arm 的 OSX 做好了准备,但 QuantLib-Python 还没有做好准备。

然后我尝试按照上面的链接从已发布的版本进行安装:

tar xzf QuantLib-SWIG-1.22.tar.gz
cd QuantLib-SWIG-1.22/Python
导出CXXFLAGS='-O2 -std=c++11 -stdlib=libc++ -mmacosx-version-min=10.9'
导出 LDFLAGS='-stdlib=libc++ -mmacosx-version-min=10.9'
python setup.py 构建

但我收到以下错误:

cd QuantLib-SWIG-1.22/Python
  export CXXFLAGS='-O2 -std=c++11 -stdlib=libc++ -mmacosx-version-min=10.9'
  export LDFLAGS='-stdlib=libc++ -mmacosx-version-min=10.9'
  python setup.py build
running build
running build_py
running build_ext
building 'QuantLib._QuantLib' extension
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -DNDEBUG -I/Users/USER/coding/project1/include -I/Users/USER/.pyenv/versions/3.9.4/include/python3.9 -I/opt/homebrew/Cellar/quantlib/1.22/include -c QuantLib/quantlib_wrap.cpp -o build/temp.macosx-11.3-arm64-3.9/QuantLib/quantlib_wrap.o -Wno-unused -O2 -std=c++11 -stdlib=libc++ -mmacosx-version-min=10.9
In file included from QuantLib/quantlib_wrap.cpp:4730:
In file included from /opt/homebrew/Cellar/quantlib/1.22/include/ql/version.hpp:28:
/opt/homebrew/Cellar/quantlib/1.22/include/ql/qldefines.hpp:38:10: fatal error: 'boost/config.hpp' file not found
#include <boost/config.hpp>
         ^~~~~~~~~~~~~~~~~~
1 error generated.
error: command '/usr/bin/clang' failed with exit code 1

我已经尝试了很多解决提升问题的方法,并查看了许多其他问题/答案,但尚未找到解决方案。是flag的问题吗?有没有人有幸让 QuantLib-Python 在基于 M1 的 OSX 上工作?

最佳答案

以下内容适用于我在 MBP M1 Max 上的工作:

  1. brew install boost

  2. brew 安装 quantlib

  3. 下载 QuantLib-SWIG-1.24.tar

    tar xzfv QuantLib-SWIG-1.24.tar

  4. cd QuantLib-SWIG-1.24/Python

    导出 CXXFLAGS='-O2 -std=c++11 -stdlib=libc++ -mmacosx-version-min=10.9 -I/opt/homebrew/Cellar/boost/1.76.0/include'

    导出 LDFLAGS='-stdlib=libc++ -mmacosx-version-min=10.9 -L/opt/homebrew/Cellar/boost/1.76.0/lib'

  5. python setup.py 构建

    python setup.py bdist_wheel

  6. cd 距离

    pip install QuantLib-1.24-cp310-cp310-macosx_11_0_arm64.whl

关于python - 在 'apple silicon' Macbook 上运行 QuantLib python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67556513/

相关文章:

python - ngram 计数后如何在数据框中添加额外的列

python - 在Python中模拟SHL和SHR ASM指令

ios - React-Native iOS XCode 版本 12.5 的旧项目的构建失败

c++ - Quantlib 已知第一现金流量与预测现金流量相等的 float 利率债券

c# - 当我从 C# 代码调用 C++ 代码时,它是线程安全的吗?

python-3.x - QuantLib:建立关键利率风险

python - Haskell 算法/糖果粉碎可能的 Action

python - 如何使用临时变量引用循环内创建的对象?

linux - 如何在 amd64 主机平台上运行 arm64 docker 镜像

macos - 通过 brew 安装 azure cli 在 mac m1 中不起作用