ImportError:无法导入名称“float\u factorial”

2024-06-26 17:51:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试安装talos(https://github.com/autonomio/talos)并将其导入我的jupyter笔记本。我在anaconda3上使用了“pip install talos”来安装它。一切都很顺利,但现在当我尝试导入talos时,出现以下错误:

import talos
ImportError: cannot import name 'float_factorial' from 'scipy._lib._util'(C:\Users\myname\Anaconda3\lib\site-packages\scipy\_lib\_util.py) 

奇怪的是,当我访问这个特定的文件夹时,有一个float_阶乘函数,所以我不清楚为什么它不起作用。是什么导致了这个问题?我应该如何解决它

提前谢谢

另外,我用的是anaconda3,Scipy1.6.1和Talos1.0


Tags: installpiphttpsimportgithubcomlibutil
1条回答
网友
1楼 · 发布于 2024-06-26 17:51:28

我找到了一个适合我的解决方案。转到C:\Users\myname\Anaconda3\lib\site packages\scipy\u lib\u util.py并编辑float\u factorial函数。 只需从以下内容重写:

def float_factorial(n: int) -> float:
    """Compute the factorial and return as a float

    Returns infinity when result is too large for a double
    """
    return float(math.factorial(n)) if n < 171 else np.inf

更简单的是,我删除了函数注释:

def float_factorial(num):
    """Compute the factorial and return as a float

    Returns infinity when result is too large for a double
    """
    val = float(math.factorial(num)) if num < 171 else np.inf
    return val

我想这与Python版本和3.8中的更改有关

相关问题 更多 >