为什么这段代码让我收到错误消息?astropy:属性错误无法导入配件

Why this code getting me error message?astropy: attribute error cannot import fitting

我想使用 astropy 来拟合光谱我的代码是:

from astropy.io import fits
from astropy.modeling import models, fitting
import math
import numpy as np
import pylab as plb
import matplotlib.pyplot as plt
#after opening  the fits file and reading its data pixel by pixel
# fitting for the spectra at a pixel
x = velocity
y = ant_tem
g_init = models.Gaussian1D(amplitude=1., mean=0, stddev=1.)
f1 = fitting.NonLinearLSQFitter()
g = f1(g_init, x,y)
# Plot the data with the best-fit model
plt.figure(figsize=(8,5))
plt.plot(x, y, 'ko')
plt.plot(x, g(x), 'r-', lw=2, label='Gaussian')
plt.xlabel('Velocity')
plt.ylabel('Antenne Temperature')
plt.legend(loc=2)

` 但是我的代码给我以下错误:

in <module>
    f1 = fitting.NonLinearLSQFitter().
AttributeError: 'module' object has no attribute 'NonLinearLSQFitter'
Please suggest what should i do?

您使用的是 astropy 0.3 或更早版本的文档。
NonLinearLSQFitter 在 astropy 0.4 及更高版本中已重命名为 LevMarLSQFitter。请改用它。