python google-re2包安装问题解决

在尝试使用pip安装google-re2的问题记录。

报错特征

× python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [177 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.macosx-10.9-x86_64-cpython-39
      copying re2.py -> build/lib.macosx-10.9-x86_64-cpython-39
      running build_ext
      building '_re2' extension
      creating build/temp.macosx-10.9-x86_64-cpython-39
      ....
      warning: alias declarations are a C++11 extension [-Wc++11-extensions]
      ....
      error: unknown type name 'constexpr'

找到源头仓库
re2/python at abseil · google/re2 (github.com)

尝试通过路径 re2/python进行编译安装

python setup.py build

你可以仍然会遇到类似报错,于是查看setup.py中的环境配置代码

ext_module = setuptools.Extension(
    name='_re2',
    sources=['_re2.cc'],
    include_dirs=list(include_dirs()),
    libraries=['re2'],
    extra_compile_args=['-fvisibility=hidden'],
)

修改为

absl_include_path = "/opt/homebrew/Cellar/abseil/20230802.1/include"
re2_include_path = "/opt/homebrew/Cellar/re2/20230901/include"
re2_lib_dir = "/opt/homebrew/lib"

ext_module = setuptools.Extension(
    name='_re2',
    sources=['_re2.cc'],
    include_dirs=list(include_dirs()) + [absl_include_path, re2_include_path],
    libraries=['re2'],
    library_dirs=[re2_lib_dir],  # This should point to the directory, not the dylib file
    extra_compile_args=['-fvisibility=hidden', '-std=c++17'],
)

其中三个路径absl_include_pathre2_include_pathre2_lib_dir可通过以下命令进行查找,或根据对应报错信息进一步调整。

find /opt/homebrew -name "libre2"
find /usr/local -name "libre2*"
ls /usr/local/lib | grep libre2
ls /opt/homebrew/lib | grep libre2

调整好setup.py之后再执行

python setup.py build
python setup.py install

即可完成安装。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

YingCai85

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值