0

我正在尝试将 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_factorial 函数,所以我不清楚为什么这不起作用。什么可能导致这个问题,我应该如何解决它?

提前致谢!

PS 我正在使用 anaconda3、scipy 1.6.1 和 talos 1.0。

4

1 回答 1

1

我找到了一个适合我的解决方案。转到 C:\Users\myname\Anaconda3\lib\site-packages\scipy_lib_util.py 并编辑 float_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 中的变化有关

于 2021-03-31T14:44:53.763 回答