Python 3.11.9导入sempy.fabric触发RecursionError问题求助
解决sempy.fabric导入时的RecursionError问题
问题场景
- 环境:VS Code + Python 3.11.9 虚拟环境
- 操作:执行导入语句
import sempy.fabric as fabric
- 报错:
RecursionError: maximum recursion depth exceeded - 完整回溯信息:
RecursionError Traceback (most recent call last) Cell In[7], line 3 1 #Conexión a modelo semántico de PBI 2 import sempy ----> 3 import sempy.fabric as fabric File c:\.venv\Lib\site-packages\sempy\fabric\__init__.py:3 1 from .._utils._telemetry import log_telemetry ----> 3 from sempy.fabric._flat import ( 4 create_lakehouse, 5 create_tom_server, 6 create_trace_connection, 7 create_notebook, 8 create_workspace, 9 delete_item, 10 evaluate_dax, 11 evaluate_measure, 12 execute_xmla, 13 execute_tmsl, 14 get_roles, 15 get_row_level_security_permissions, 16 get_refresh_execution_details, 17 get_tmsl, 18 list_items, ... ---> 46 arg_str = _construction_repr(dtype, include_align=False) 47 if dtype.isalignedstruct: 48 arg_str = arg_str + ", align=True"
可能的解决方法
1. 调整sempy版本
部分sempy版本与Python 3.11.9存在兼容性问题,导致导入时触发递归死循环。尝试切换到经测试兼容的版本:
pip uninstall sempy -y pip install sempy==0.10.0
2. 临时提高Python递归深度
Python默认递归深度限制为1000,若库内部导入逻辑递归调用超过该值,可临时调整:
import sys sys.setrecursionlimit(2000) import sempy.fabric as fabric
注意:此方法仅作为临时排查手段,不建议长期使用,避免引发其他潜在问题。
3. 重建虚拟环境
虚拟环境文件损坏可能导致库导入异常,删除现有环境后重新创建:
# Windows系统删除虚拟环境 rd /s /q c:\.venv # 重新创建并激活 python -m venv c:\.venv c:\.venv\Scripts\activate # 重新安装sempy pip install sempy
4. 检查依赖包版本冲突
sempy的依赖库(如numpy、pandas)版本不兼容也可能引发该问题,可强制更新核心依赖:
pip install --upgrade numpy pandas
内容的提问来源于stack exchange,提问作者Pluvia
相关产品推荐
相关产品推荐

