ImportError: cannot import name 'SplineModel' from 'lmfit.models'

174 Views Asked by At

I am trying to use SplineModel to fit background noise as part of a Composite Model to fit a peak and a background using lmfit as per the documentation here:

lmfit SplineModel example

However when trying to import the SplineModel package using:

from lmfit.models import SplineModel

I get the error raised above (ImportError: cannot import name 'SplineModel' from 'lmfit.models') followed by the directory where the lmfit/models.py resides. I have tried to get the most recent lmfit from the lmfit GitHub advice page also, and tried to update according to conda install -c gsecars lmfit which did not work either.

I have also tried:

from lmfit.models import *

But this raises the error: NameError: name 'SplineModel' is not defined. Does anyone know why I am getting the error? Is it some compatibility issue perhaps? For your information, I am using Python version 3.9 with Spyder as part of the Anaconda package.

1

There are 1 best solutions below

0
M Newville On

SplineModel was introduced in version 1.1.0, so your version of lmfit is likely out-of-date. You'll want to update with pip install --upgrade lmfit.

FWIW, you could also use conda to install the lmfit package from conda-forge, but the result will not be different and conda will take much longer.