AttributeError: partially initialized module 'sympy' has no attribute 'S' (most likely due to a circular import)

AttributeError: partially initialized module 'sympy' has no attribute 'S' (most likely due to a circular import)

这是我的代码

x,t = sympy.S('x,t')

def dawson(i):
    x = i
    expression = sympy.E**(-x**2) * sympy.integrate(sympy.E**(t**2),t,0,x)
    return sympy.lamdify(expression)

但是我在执行它时遇到了那个奇怪的错误,这是第一次发生这种情况。为什么 sympy 部分 初始化,循环导入在这里意味着什么?

不太确定这是否有帮助,但发布这个答案是因为我使用不同的模块时发生了这个错误requests (python -m pip install requests),这就是我修复它的方法。

这件事发生在我身上,因为我将文件命名为 random.py,它也恰好是 python 的标准库中的一个模块的名称。

MCVE

import requests
requests.get(None)

将文件另存为 random.py 和 运行。

AttributeError: partially initialized module 'requests' has no attribute 'get' (most likely due to a circular import)

将文件重命名为其他名称为我解决了这个问题。

所以我的猜测是不要将您的文件命名为与 python 的任何 stdlib 模块相同的名称,并且在您当前的工作目录中不要有任何与名称相同的 .py 文件好吧(如果您一开始就遵循之前的建议,则不太可能)。