当我尝试运行以下代码时,此代码位于名为 plot.py
的脚本中import sys
# Python Qt4 bindings for GUI objects
from PyQt4 import QtGui
# Numpy functions for image creation
import numpy as np
# Matplotlib Figure object
from matplotlib.figure import Figure
# import the Qt4Agg FigureCanvas object, that binds Figure to
# Qt4Agg backend. It also inherits from QWidget
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
class Qt4MplCanvas(FigureCanvas):
"""Class to represent the FigureCanvas widget"""
def __init__(self):
# Standard Matplotlib code to generate the plot
self.fig = Figure()
self.axes = self.fig.add_subplot(111)
self.x = np.arange(0.0, 3.0, 0.01)
self.y = np.cos(2*np.pi*self.x)
self.axes.plot(self.x, self.y)
# initialize the canvas where the Figure renders into
FigureCanvas.__init__(self, self.fig)
# Create the GUI application
qApp = QtGui.QApplication(sys.argv)
# Create the Matplotlib widget
mpl = Qt4MplCanvas()
# show the widget
mpl.show()
# start the Qt main loop execution, exiting from this script
# with the same return code of Qt application
sys.exit(qApp.exec_())
我得到了完整的错误详情,
File "C:/Users/Admin/PycharmProjects/pqt4gui/plot.py", line 5, in <module>
import numpy as np
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\numpy\core\__init__.py", line 74, in <module>
from numpy.testing.nosetester import _numpy_tester
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\numpy\testing\__init__.py", line 12, in <module>
from . import decorators as dec
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\numpy\testing\decorators.py", line 20, in <module>
from .utils import SkipTest, assert_warns
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\numpy\testing\utils.py", line 15, in <module>
from tempfile import mkdtemp, mkstemp
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36-32\lib\tempfile.py", line 45, in <module>
from random import Random as _Random
ImportError: cannot import name 'Random'
我是编程的新手,我对这个错误进行了一些研究,而且非常有成效。