提问人:Donya 提问时间:3/13/2023 更新时间:3/13/2023 访问量:286
ImportError:无法从“textstat.textstat”导入名称“legacy_round”
ImportError: cannot import name 'legacy_round' from 'textstat.textstat'
问:
我正在尝试从以下位置导入:legacy_round
textstat
from textstat.textstat import textstatistics,legacy_round
但是我收到以下错误:ImportError: cannot import name 'legacy_round' from 'textstat.textstat'
知道如何解决这个问题吗?
答:
0赞
Abdulmajeed
3/13/2023
#1
legacy_round已从最新版本中删除,您可能使用的是旧版本。
您可以尝试将 textstat 包降级到包含它的版本:
pip install textstat==0.6.2
或者,您可以使用 Python 标准库中的 round 函数来代替 legacy_round:
from textstat.textstat import textstatistics
import math
flesch_reading_ease = textstatistics().flesch_reading_ease(text)
flesch_reading_ease_rounded = math.floor(flesch_reading_ease + 0.5)
0赞
Timeless
3/13/2023
#2
根据 (#186) 中的@alxwrd,您需要使用 _legacy_round
而不是 .legacy_round
from textstat.textstat import textstatistics
#add these two lines
from textstat import textstat
legacy_round = textstat._legacy_round
评论