我通过Anaconda 3(Python3.7)和Designer用PyQt5开发了一个“不那么简单”的GUI。我在我的程序中导入了3个不同的.ui文件。
当我运行cx_Freeze时,一切都运行良好,我创建了.exe。然后,我从cx_Freeze创建的"Build“文件夹中的"Python”文件夹复制"platform“文件夹。
但是,当我把它传递给另一台没有任何东西的机器时(没有蟒蛇,没有蟒蛇,没有cx_Freeze,什么都没有),这个应用程序就无法运行。我得到:
ImportError: DLL load failed: The specified module could not be found
这发生在我代码的第10行,即:
from PyQt5 import QtGui, QtWidgets
我的代码中的导入是:
from PyQt5 import QtGui, QtWidgets
import sys
import glob
import datetime
from matplotlib.backends.qt_compat import QtCore, QtWidgets
from matplotlib.backends.backend_qt5agg import FigureCanvas
from matplotlib.figure import Figure
import numpy as np
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import design
import flex
import entry
design
、flex
和entry
是.ui文件。它们最后都包含了这个部分(不知道是否有用):
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())
最后,我使用cx_Freeze运行的安装文件:
import sys
from cx_Freeze import setup, Executable
import matplotlib
import numpy
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os", "matplotlib"], "includes": ["PyQt5", "atexit"], "excludes": ["tkinter"]}
# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup( name = "Flexicounts",
version = "0.1",
description = "Flexicounts pour faire tes comptes facilement",
options = {"build_exe": build_exe_options},
executables = [Executable("flexicounts.py", base=base)])
我读了很多关于它的书,但我觉得没有“奇迹”的解决办法.
你能帮我冻结我的应用程序,让它在“处女膜”上运行吗?
发布于 2019-09-20 08:33:54
您可能正面临着第504期的cx_Freeze存储库。在这种情况下,引用marceloduarte的评论:
解决方法是将
python3.dll
复制到生成可执行文件的目录中。cx_Freeze复制python37.dll
,但不复制python3.dll
。当系统上不再存在vcruntime140.dll
时,也可能不得不复制它。
首先,尝试手动将这些DLL(在包含python.exe的python安装目录中找到)复制到可执行文件的目录中。如果这解决了问题,您可以通过使用cx_Freeze的include_files
列表告诉build_exe_options
为您做这件事。按以下方式修改安装脚本:
import os
python_dir = os.path.dirname(sys.executable) # directory of your python installation
build_exe_options = {"packages": ["os", "matplotlib"],
"includes": ["PyQt5", "atexit"],
"include_files": [os.path.join(python_dir, "python3.dll"), os.path.join(python_dir, "vcruntime140.dll")],
"excludes": ["tkinter"]}
也许您需要复制更多的DLL,比如msvcp140.dll
,或者msvcp140.dll
安装的site-packages/PyQt5
目录(包括子目录)中的任何其他DLL。
发布于 2022-03-10 11:01:21
最近,我遇到了一个类似的问题,有以下版本:
python 3.6.6 x64
cx-Freeze==6.10
PyQt5==5.15.4
PyQt5-Qt5==5.15.2
PyQt5-sip==12.9.0
PyQt5-stubs==5.15.2.0
PyQtWebEngine==5.15.5
PyQtWebEngine-Qt5==5.15.2
症状:
cx_Freeze包是成功的,并且在我的机器上执行得很好,因为(正如我稍后所发现的,并在下面解释)我已经通过环境变量在我的机器上安装了Python3.6 x64和visi胆。
在另一台计算机上,该包在第一次PyQt5导入时发生了完全相同的错误:
ImportError: DLL load failed: The specified module could not be found
然而,在我的例子中,所有必要的all似乎都在正确的位置:
python3.dll
和python36.dll
放在可执行文件的旁边。但是没有复制其他dll (例如,没有vcruntime140.dll )有效的解决办法:
(我创建了一个冻结问题)
与其他答案相反,我不得不复制
python3.dll
(either from <cx_freeze_build_dir_target> or from python3.6.6 install dir ...)
(python36.dll works too but is much bigger)
进入下列文件夹:
<cx_freeze_build_dir_target>/lib/PyQt5/
对应的cx_Freeze设置配置将以以下方式将其添加到include_files
列表中。
不幸的是,不工作,因为cx_Freeze有一种异常文件列表,其中包括python3.dll
,并通过include_files
阻止实际的副本。所以,拷贝应该手动执行,在完全安装脚本执行之后.
# import pkgutil
from pathlib import Path
from glob import glob
import sys
# ... your stuff
#
includes_list = []
# your stuff
# ...
# pyqt5 force copy of pythonlib(s) into qt5 target dir
# may not work if you intend to zip pyqt5 ?
python_dir = Path(sys.executable).parent
python_dlls = [ Path(p) for p in glob(f"{python_dir.as_posix()}/python*.dll")]
pyqt_base_dir = Path("lib", "PyQt5")
# prepare cx_Freeze tuples (source file, target dir)
includes_list+= [ (p, pyqt_base_dir / p.name) for p in python_dlls ]
build_exe_options = {"packages" : ..., # your packages
"includes" : ..., # yours
"include_files": includes_list,
"excludes" : ... # yours
}
https://stackoverflow.com/questions/58018779
复制相似问题