如何在Windows 10上使用Cx_Freeze创建包括PyQt5和OpenCV的exe

时间:2018-02-28 07:30:18

标签: python opencv pyqt5 python-3.5 cx-freeze

我正在使用Python 3.5.4并试图通过以下设置使用Cx_Freeze制作'exe':

import cx_Freeze
import sys
import PyQt5 
import matplotlib
import numpy
import cv2

base = None

if sys.platform == 'win32':
    base = "Win32GUI"

executables = [cx_Freeze.Executable("Halcon_Reborn_Python_GUI.py", base=base, icon="tdic.ico")]

cx_Freeze.setup(
name = "Halcon Reborn",
options = {"build_exe": {"packages":["PyQt5","matplotlib","numpy","OpenCV"], "include_files":["tdic.ico"]}},
version = "0.01",
description = "Halcon Reborn Python GUI with ROI",
executables = executables
)

但是当我执行setup.py

我收到以下错误

以下是我的GUI python文件中的导入:

import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QMenu, QVBoxLayout, QSizePolicy, QMessageBox
from PyQt5.QtWidgets import QFileDialog, QLabel, QWidget, QPushButton,QDialog,QDialogButtonBox
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import Qt 
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
from numpy.lib.stride_tricks import as_strided as ast
from itertools import product
import matplotlib.pyplot as plt
import timeit
import numpy as np
import random
import cv2
import ctypes

1 个答案:

答案 0 :(得分:0)

以下是解决我问题的代码:

import cx_Freeze
import sys 
import matplotlib
import numpy
import cv2
import os
import ctypes
import timeit
import tkinter

base = None

if sys.platform == 'win32':
    base = "Win32GUI"

executables = [cx_Freeze.Executable("Halcon_Reborn.py", base=base, icon="tdic1.ico")]
os.environ['TCL_LIBRARY'] = r'C:\Users\danial khan\AppData\Local\Programs\Python\Python35\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\danial khan\AppData\Local\Programs\Python\Python35\tcl\tk8.6'
cx_Freeze.setup(
name = "Halcon Reborn",
options = {"build_exe": {"packages":["tkinter","PyQt5.QtCore","PyQt5.QtGui", "PyQt5.QtWidgets","ctypes","timeit","matplotlib","numpy","cv2"], "include_files":[r"C:\Users\danial khan\AppData\Local\Programs\Python\Python35\Lib\site-packages\PyQt5\plugins\platforms\qwindows.dll",r"C:\Users\danial khan\AppData\Local\Programs\Python\Python35\DLLs\tcl86t.dll",r"C:\Users\danial khan\AppData\Local\Programs\Python\Python35\DLLs\tk86t.dll","tdic1.ico"]}},
version = "0.01",
author='Muhammad Danial Khan',
description = "Halcon Reborn Python GUI with ROI",
executables = executables
)