【发布时间】:2025-12-05 12:50:02
【问题描述】:
我在 ipython 中导入 lmfit 时遇到问题。
使用 python 2.7.9 运行 ipython 2.30:
导入 lmfit 会产生两个错误:
1)
/home/cfigura/.local/lib/python2.7/site-packages/lmfit/ui/ipy_fitter.py in <module>()
14 # Handle the change in naming from 2.x to 3.x.
15 if IPython.release.version_info[0] == 2:
---> 16 from IPython.html.widgets import DropdownWidget as Dropdown
17 from IPython.html.widgets import ButtonWidget as Button
18 from IPython.html.widgets import ContainerWidget as Box
ImportError: No module named html.widgets
如果我尝试重新导入,该错误就会消失,我会得到以下信息:
In [2]: import lmfit
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-2-58ac0858c54d> in <module>()
----> 1 import lmfit
/home/cfigura/.local/lib/python2.7/site-packages/lmfit/__init__.py in <module>()
42
43 from .model import Model, CompositeModel
---> 44 from . import models
45
46 from . import uncertainties
ImportError: cannot import name models
重新运行导入时,此错误不会消失。
如果我 不 使用 ipython 而只是导入到普通的 python shell,我没有错误/问题。显然与 ipython 存在某种冲突!
有没有人看到类似的东西,或者可以指出我正确的方向来解决这个问题?马哈洛!
【问题讨论】:
-
如果您使用 apt-get 安装了 IPython,我认为确保安装了
ipython-notebook应该可以解决该错误。不过,您可能会遇到另一个问题 - 看起来 lmfit 假设在 IPython 中运行的任何东西都在笔记本中运行。 -
Thomas K - 安装 ipython-notebook did 解决了这个问题。我会做一些额外的测试来验证 lmfit 是否正常工作,但是导入成功了!谢谢!