Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
User interface cx#U冻结错误生成PyQT5+;Matplotlib Python 3应用程序_User Interface_Deployment_Matplotlib_Cx Freeze_Pyqt5 - Fatal编程技术网

User interface cx#U冻结错误生成PyQT5+;Matplotlib Python 3应用程序

User interface cx#U冻结错误生成PyQT5+;Matplotlib Python 3应用程序,user-interface,deployment,matplotlib,cx-freeze,pyqt5,User Interface,Deployment,Matplotlib,Cx Freeze,Pyqt5,我在为我使用的应用程序编译可执行文件时遇到问题: -Python 3.3 -PyQT5 -Matplotlib 我尝试将Cx\U Freeze与此setup.py一起使用: import sys from cx_Freeze import setup, Executable includes = ['sys','PyQt5.QtCore','PyQt5.QtGui', 'PyQt5.QtWidgets','matplotlib'] excludes = [] packages = [] path

我在为我使用的应用程序编译可执行文件时遇到问题: -Python 3.3 -PyQT5 -Matplotlib

我尝试将Cx\U Freeze与此setup.py一起使用:

import sys
from cx_Freeze import setup, Executable
includes = ['sys','PyQt5.QtCore','PyQt5.QtGui', 'PyQt5.QtWidgets','matplotlib']
excludes = []
packages = []
path = []
base = None
if sys.platform == 'win32':
    base = 'Win32GUI'
options = {
    'build_exe': {
        "includes": includes,
        "excludes": excludes,
        "packages": packages,
        "path": path
        #'excludes': ['Tkinter']  # Sometimes a little finetuning is needed
    }
}
executables = [Executable('pyqt5_matplotlib.py', base=base)]
setup(name='pyqt5_matplotlib',
      version='0.1',
      description='Sample PyQT5-matplotlib script',
      executables=executables,
      options=options
      )
运行setup.py生成包含各种DLL的文件夹并创建exe时,此时没有错误。 运行由此创建的exe时,我遇到以下错误:

有人能帮我吗

出于这个问题的目的,我将包括一个示例主脚本,它在构建时会复制错误:

# @author: Sukhbinder Singh
#  
# Simple QTpy and MatplotLib example with Zoom/Pan
#  
# Built on the example provided at
# How to embed matplotib in pyqt - for Dummies
#  
# http://stackoverflow.com/questions/12459811/how-to-embed-matplotib-in-pyqt-for-dummies
#  
# """
import sys
from PyQt5.QtWidgets import (QApplication, QCheckBox, QColorDialog, QDialog,
        QErrorMessage, QFileDialog, QFontDialog, QFrame, QGridLayout,
        QInputDialog, QLabel, QLineEdit, QMessageBox, QPushButton, QWidget, QVBoxLayout )
from PyQt5.QtCore import pyqtSlot, QDir, Qt
from PyQt5 import QtGui
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QTAgg as NavigationToolbar
import matplotlib.pyplot as plt
import numpy
import random

class Window(QDialog):
    def __init__(self, parent=None):
        super(Window, self).__init__(parent)

        self.figure = plt.figure()
        self.canvas = FigureCanvas(self.figure)

        self.toolbar = NavigationToolbar(self.canvas, self)
        #self.toolbar.hide()

        # Just some button 
        self.button = QPushButton('Plot')
        self.button.clicked.connect(self.plot)

        self.button1 = QPushButton('Zoom')
        self.button1.clicked.connect(self.zoom)

        self.button2 = QPushButton('Pan')
        self.button2.clicked.connect(self.pan)

        self.button3 = QPushButton('Home')
        self.button3.clicked.connect(self.home)

        # set the layout
        layout = QVBoxLayout()
        layout.addWidget(self.toolbar)
        layout.addWidget(self.canvas)
        layout.addWidget(self.button)
        layout.addWidget(self.button1)
        layout.addWidget(self.button2)
        layout.addWidget(self.button3)
        self.setLayout(layout)

    def home(self):
        self.toolbar.home()
    def zoom(self):
        self.toolbar.zoom()

    def pan(self):
        self.toolbar.pan()

    def plot(self):
        #''' plot some random stuff '''

        #data = [random.random() for i in range(25)]
        data_matrix = numpy.random.random((256,256))
        ax = self.figure.add_subplot(111)
        ax.hold(False)

        #ax.plot(data, '*-')
        ax.imshow(data_matrix)
        self.canvas.draw()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    main = Window()
    main.setWindowTitle('Simple QTpy and MatplotLib example with Zoom/Pan')
    main.show()
    sys.exit(app.exec_())

经过更深入的研究,我做了以下工作:

  • 已安装PyWin32
  • 已安装cx_Freeze的测试版(可能不需要)
  • 编辑python33/Lib/site packages/matplotlib/mpl data/matplotlibrc,以便第32行:
后端:tkAgg

变成

backend: Agg
最后一个消息来源是


此解决方案适用于Win 7 64位和Python3.3,用于带有Matplotlib后端的单窗口PyQT5。

您也可以尝试将Matplotlib放在“包”中而不是“包含”中,这将使其包含所有子模块。我在搜索此问题时偶然发现了您的问题,仅使用步骤3:修复matplotlibrc文件解决了此问题。