似乎无法在spyder上导入pyqt_fit

时间:2017-12-14 17:07:42

标签: python-2.7 pyqt spyder

我一直在使用Atom.io来运行我的python代码,但最近我无法运行需要pyqt_fit的代码。我在Atom上找不到允许我运行pyqt的任何软件包。因此,我下载了anaconda和spyder。我使用自制软件来安装qt,sip和pyqt。

在Spyder中,我尝试执行以下操作:

import pyqt_fit
from pyqt_fit import plot_fit
import numpy as np
from matplotlib import pylab

x = np.arange(0,3,0.01)
y = 2*x + 4*x**2 + np.random.randn(*x.shape)
def fct(params, x):
    (a0, a1, a2) = params
    return a0 + a1*x + a2*x*x
fit = pyqt_fit.CurveFitting(x, y, (0,1,0), fct)
result = plot_fit.fit_evaluation(fit, x, y)
print(fit(x)) # Display the estimated values
plot_fit.plot1d(result)
pylab.show()

但我收到了以下错误:

runfile('/Users/Griffin/Atom/FYP Bifurcations/untitled1.py', wdir='/Users/Griffin/Atom/FYP Bifurcations')
Reloaded modules: pyqt_fit.utils, pyqt_fit.compat
Traceback (most recent call last):

  File "<ipython-input-24-effdfa66efe9>", line 1, in <module>
runfile('/Users/Griffin/Atom/FYP Bifurcations/untitled1.py', wdir='/Users/Griffin/Atom/FYP Bifurcations')

  File "/anaconda/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 710, in runfile
execfile(filename, namespace)

  File "/anaconda/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 93, in execfile
builtins.execfile(filename, *where)

  File "/Users/Griffin/Atom/FYP Bifurcations/untitled1.py", line 9, in <module>
import pyqt_fit

  File "pyqt_fit/__init__.py", line 14, in <module>
from . import functions, residuals

  File "pyqt_fit/functions/__init__.py", line 6, in <module>
from .. import loader

  File "pyqt_fit/loader.py", line 3, in <module>
from path import path

ImportError: cannot import name path

它与我放置pyqt_fit文件夹的位置有什么关系吗? 提前谢谢!

1 个答案:

答案 0 :(得分:1)

根据PyQt-Fit requirements filepath.py包是一个依赖项。但是,PyQt-Fit package自2015-02-11以来尚未更新,并且已对path.py进行了不相容的更改,但未对其进行跟踪。问题中的具体错误是由this change引起的,该{{3}}删除了path作为Path类的别名。

要解决此问题,您可以尝试像这样修补path.py

# before pyqt_fit is first imported
import path
path.path = path.Path

import pyqt_fit
from pyqt_fit import plot_fit

或者,您可以将path.py降级为任何版本&gt; = 2.4并且&lt; 8.0。