如何在 Windows 10 上使用 Cx_Freeze 制作 exe,包括 PyQt5 和 OpenCV
Posted
技术标签:
【中文标题】如何在 Windows 10 上使用 Cx_Freeze 制作 exe,包括 PyQt5 和 OpenCV【英文标题】:How to make exe with Cx_Freeze including PyQt5 and OpenCV on Windows 10 【发布时间】:2018-08-08 00:16:50 【问题描述】:我正在使用 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】:这是解决我问题的代码:
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
)
【讨论】:
"PyQt5\Qt\plugins\platforms" plugins 文件夹现在位于 Qt 文件夹下 那些包名也全错了。应该是小写以上是关于如何在 Windows 10 上使用 Cx_Freeze 制作 exe,包括 PyQt5 和 OpenCV的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 USB 声卡在 Windows 10 上启用 android 模拟器声音?
如何在 Windows 10 上使用 Powershell 将 Google Colab 与本地 TensorFlow Jupyter 服务器一起使用?