Azure Databricks导入camelot包时遇'numpy._DTypeMeta'不可下标错误
问题:Azure Databricks中导入camelot报错TypeError: 'numpy._DTypeMeta' object is not subscriptable
环境与操作说明
- 运行环境:Azure Databricks
- 已执行的依赖安装命令:
!pip install PyPDF2!pip install bs4!pip install camelot-py[cv]!pip install tabula-py
- 使用的导入代码:
from urllib import request import requests import traceback import re import os import urllib import tabula from tabula.io import read_pdf from pathlib import Path import numpy as np import camelot
- 触发的错误:
TypeError: 'numpy._DTypeMeta' object is not subscriptable
解决方案
这个错误是numpy版本与camelot-py不兼容导致的——numpy 1.24+版本调整了数据类型元类的写法,而camelot-py现有代码仍沿用旧版numpy语法。按以下步骤修复:
- 卸载当前numpy,安装兼容的旧版本(推荐1.23.5):
!pip uninstall -y numpy !pip install numpy==1.23.5
- 重启Azure Databricks集群,确保依赖生效。
- 重新运行导入代码验证,可先检查numpy版本确认安装成功:
import numpy as np print(np.__version__) # 输出应为1.23.5 import camelot
内容的提问来源于stack exchange,提问作者bigdata techie
相关产品推荐
相关产品推荐

