python - 名称“sympy”未定义
问题描述
昨天我的代码运行良好,但今天 jupyter 无法识别 sympy,我已经检查并安装了它,我该怎么办?
from sympy import expand, symbols
x0=2
y0=4
x1=5
y1=1
x =symbols("x")
L0=sympy.expand((x-x1)/(x0-x1))*y0
L1=sympy.expand((x-x0)/(x1-x0))*y1
print ("L0= ",L0)
print ("L1= ",L1)
print ("px= ",L0+L1)
错误堆栈跟踪:
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-3-9cbabedcf78d> in <module>
9 x =symbols("x")
10
---> 11 L0=sympy.expand((x-x1)/(x0-x1))*y0
12 L1=sympy.expand((x-x0)/(x1-x0))*y1
13
NameError: name 'sympy' is not defined
解决方案
由于您已扩展已导入,如下所示:
from sympy import expand, symbols
像这样运行这两行而不像这样使用sympy.
:
L0=expand((x-x1)/(x0-x1))*y0
L1=expand((x-x0)/(x1-x0))*y1
另外,以防万一在您的 jupyter notebook 中运行它并确保sympy
已安装:
pip list
推荐阅读
- python - 无法使用 docker 和 tox 连接到 Postgres 服务
- swift - 如何仅为 git diff 文件运行 swiftlint
- c# - 这种类型的文件可能会损害您的计算机,尝试使用 c# 和 selenium 在 Chrome 中下载 .ini 文件
- android - 我们可以在“native-base”的页脚组件的列中设置两个按钮,还是可以设置“native-base”的页脚高度?
- python-3.x - 如何在用户交互脚本中创建一个循环,可以在图像系列中添加任意数量的标签?
- nested - 在 ionic4 中使用嵌套子路由时,路由在一次主导航更改后停止工作
- javascript - 清除 max-Date 时出现无效日期错误
- vba - 根据电子邮件标题创建文件夹并将电子邮件移动到该文件夹
- ios - 以编程方式获取嵌入在 UIStackView 中的自定义 UIView
- javascript - 通过 W3C Web Payments API 进行方形多方交易