我正在尝试使用cx_Freeze打包我的应用程序Python3,PyQt5 for Windows。 我已经安装了Python 3.4.3,Python-win32,PyQT5,cxfreeze。 应用程序本身,在控制台中运行,工作正常。
我尝试用cx_freeze打包它: python setup.py build_exe。 它适用于同一主机。但当我将它移动到另一个干净的安装WinXP时,它会出错:
Traceback:
File "C:\Python34\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27 in <module>
File "pyftp1.py" in 7, in <module>
File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", in 2237, in _find_and_load
File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", in 2226, in _find_and_load_unlocked
File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", in 1191, in _load_unlocked
File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", in 1161, in _load_backward_compatible
File "ExtensionLoader_PyQt5_QtWidgets.py", line 22, in <module>
File "ExtensionLoader_PyQt5_QtWidgets.py", line 14, in __bootstrap__
ImportError: DLL load failed: Не найден указанный модуль.
英语:&#34;未找到指定的模块&#34;。
这是我的setup.py:
import sys
from cx_Freeze import setup, Executable
includes = ['sys', 'PyQt5', 'PyQt5.Core', 'PyQt5.QtGui', 'PyQt5.QtWidgets', 'os', 'os.path', 'ftplib',
'traceback', 'time',]
excludes = []
packages = ['os', 'PyQt5']
path = []
build_exe_options = {
'includes': includes,
'excludes': excludes,
'packages': packages,
'path' : path,
#'dll_includes': ['msvcr100.dll'],
'include_msvcr' : True,
'include_files': [
(r'C:\Windows\System32\msvcr100.dll', 'msvcr100.dll'),
],
}
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
setup(
name = "pyftp1",
version = "0.1",
description = "Foto uploader",
options = {'build_exe_options': build_exe_options},
executables = [Executable("pyftp1.py", base=base, appendScriptToLibrary=False, copyDependentFiles=True)]
)
另外我发现它没有复制msvcr100.dll文件,但是我已经说过两次了!我已将其手动复制到目标主机。
这里是pyftp1.py:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys, time, os, hashlib
import ftplib
import traceback
from PyQt5.QtWidgets import QApplication, QWidget, QFileDialog # <-- Line 7
from PyQt5.QtWidgets import QPushButton, QHBoxLayout, QVBoxLayout, QScrollArea, QLineEdit, QCheckBox
from PyQt5 import QtGui
from PyQt5.QtGui import QIcon, QPalette, QLinearGradient, QColor, QBrush
from PyQt5.QtCore import QObject, QThread, pyqtSignal, pyqtSlot
答案 0 :(得分:4)
在很长一段时间遇到问题后我找到了解决方案。许多如何不使用帐户特定版本的软件,或使用某些特定模块,甚至他们不检查新系统上的.exe,它没有你的库dll等等。这是工作和测试的解决方案。
首先,我删除了cx_freeze并使用了py2exe。 我已经在WinXP 32位上构建了所有的东西 - 为了它的目标它几乎可以在每个系统上运行。 你需要:
接下来,我将setup.py添加到项目中:
from distutils.core import setup
import os, sys
import py2exe
from glob import glob
import PyQt5
NAME="ProgName"
qt_platform_plugins = [("platforms", glob(PyQt5.__path__[0] + r'\plugins\platforms\*.*'))]
data_files.extend(qt_platform_plugins)
msvc_dlls = [('.', glob(r'C:\Windows\System32\msvc?100.dll'))]
data_files.extend(msvc_dlls)
# print(data_files)
sys.argv.append('py2exe')
setup(
data_files=data_files,
# windows=["pyftp1.py",],
windows=[
{
"script": "pyftp1.py",
"icon_resources": [(0, "resources/favicon.ico")]
}
],
# zipfile=None,
options={
"py2exe": {
"includes":["sip", "atexit",],
# "packages": ['PyQt5'],
"compressed": True,
"dist_dir": "dist/" + NAME,
# "bundle_files": 0,
# "zipfile": None,
"optimize": 2,
}
}
)
只是不要手动运行所有操作,您可以添加Makefile
# start settings
DIST=dist
# change NAME also in setup.py and resource/config.txt
NAME=ProgName
EXT=exe
# final name and location of the built program
FINAL=$(DIST)/$(NAME).$(EXT)
# external programs
7ZIPDIR="C:\Program Files\7-Zip"
RESHACKER="/c/Program\ Files/Resource\ Hacker/ResourceHacker.exe"
# intermediate steps
# no icon version of program
NOICON=$(DIST)/$(NAME)_no_icon.$(EXT)
# name of .7z archive
7Z_BASENAME=$(NAME).7z
7Z=$(DIST)/$(7Z_BASENAME)
# folder with ready .exe
PROGDIR=$(DIST)/$(NAME)
all: $(FINAL)
$(FINAL): $(NOICON)
# change icon
"$(RESHACKER)" -addoverwrite $(NOICON), $(FINAL), resources/favicon.ico, ICONGROUP, MAINICON, 0
$(NOICON): $(7Z)
#build autorunning sfx with default icon
cat $(7ZIPDIR)/7zS.sfx resources/config.txt $(7Z) > $(NOICON)
$(7Z): exe
# compress program folder to .7z
cd $(DIST); $(7ZIPDIR)\\\7z.exe a $(7Z_BASENAME) $(NAME)
exe: $(DIST)
# build program itself
python setup.py py2exe
$(DIST):
# create dist directory
# echo $(DIST)/
clean:
rm -rf $(DIST)/*
现在您可以轻松地构建程序 - 作为文件的文件夹: mingw32-make.exe exe 或者使用正确的图标制作单个文件: mingw32-make.exe全部 或清理所有的东西: mingw32-make.exe清理
答案 1 :(得分:0)
将'libEGL.dll'添加到您的工作文件夹中。这是来自Python3x \ Lib \ site-packages \ PyQt5
在cx-freeze setup.py中添加:
如果sys.platform ==“win32”: includefiles = ['libEGL.dll']#如果需要,你应该添加其他文件
在cx-freeze setup.py链接“includefiles”到build_exe_options,如下所示:
build_exe_options = { ... ... 'include_files':includefiles, }