我想从windowz(xp, 7, ...)
脚本为python3(+ PyQt5)
构建一个独立的二进制文件,我不可避免地使用cx_freeze
,因为其他冻结的应用程序不能与python3一起使用(如py2exe
,pyinstaller
)。
我阅读了cx_freeze
文档,并且有很多stackoverflow请求将此配置用于setup.py
文件:
import sys
from cx_Freeze import setup, Executable
path_platforms = ( "C:\Python33\Lib\site-packages\PyQt5\plugins\platforms\qwindows.dll", "platforms\qwindows.dll" )
includes = ["atexit","PyQt5.QtCore","PyQt5.QtGui", "PyQt5.QtWidgets"]
includefiles = [path_platforms]
excludes = [
'_gtkagg', '_tkagg', 'bsddb', 'curses', 'email', 'pywin.debugger',
'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl',
'Tkconstants', 'Tkinter'
]
packages = ["os"]
path = []
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {
"includes": includes,
"include_files": includefiles,
"excludes": excludes,
"packages": packages,
"path": path
}
# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
exe = None
if sys.platform == "win32":
exe = Executable(
script="D:\\imi\\aptanaWorKPCworkspace\\azhtel\\tel.py",
initScript = None,
base="Win32GUI",
targetDir = r"dist",
targetName="tel.exe",
compress = True,
copyDependentFiles = True,
appendScriptToExe = False,
appendScriptToLibrary = False,
icon = None
)
setup(
name = "telll",
version = "0.1",
author = 'me',
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [exe]
)
运行:
python D:\imi\aptanaWorKPCworkspace\azhtel\setup.py build
这是我用过的图书馆:
from PyQt5 import QtGui, QtCore, QtWidgets
import sys
from telGui import Ui_MainWindow
import mysql
import mysql.connector
from mysql.connector import errorcode
这是我在工作区中的文件:
但是发生了这个错误(或其他类型的错误)。
为什么会发生这种情况以及setup.py
的配置对pyqt5 app有什么好处?
Python3.3,PyQt5,Mysqlconnector。
答案 0 :(得分:1)
我解决了这个问题,找到名为build
的dist目录附近的另一个目录,所有库文件都在那里,我删除了targetDir = r"dist"
的{{1}}部分,并且每件事都没问题!
答案 1 :(得分:0)
尝试使用pyinstaller。它比cxfreeze好得多。