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

即可完成安装。

要爬取谷歌学术文献信息,你可以使用 Python 的 requests、BeautifulSoup 和 re 库来实现。 以下是一个简单的代码示例,可以帮助你获取谷歌学术搜索结果页面的 HTML 代码,并从中提取出每篇文献的标题、作者、摘要和链接: ```python import requests from bs4 import BeautifulSoup import re # 搜索关键词 query = 'python web scraping' # 构造查询字符串 params = {'q': query} # 定义请求头 headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'} # 发送 GET 请求并获取响应 response = requests.get('https://scholar.google.com/scholar', params=params, headers=headers) # 解析 HTML 代码 soup = BeautifulSoup(response.text, 'html.parser') # 提取每篇文献的信息 articles = soup.find_all('div', {'class': 'gs_ri'}) for article in articles: # 提取标题 title = article.find('h3', {'class': 'gs_rt'}).text.strip() # 提取作者 authors = article.find('div', {'class': 'gs_a'}).text.strip() authors = re.sub(r'\xa0', '', authors) authors = re.split(' - ', authors) # 提取摘要 abstract = article.find('div', {'class': 'gs_rs'}).text.strip() # 提取链接 link = article.find('h3', {'class': 'gs_rt'}).find('a')['href'] # 打印结果 print('Title:', title) print('Authors:', authors) print('Abstract:', abstract) print('Link:', link) print('-------------------') ``` 这段代码会输出每篇文献的标题、作者、摘要和链接。你可以根据需求修改代码,提取更多或更少的信息。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

YingCai85

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

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

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

打赏作者

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

抵扣说明:

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

余额充值