【发布时间】:2019-10-08 13:26:26
【问题描述】:
问题:
我无法将 cx_freeze 生成的 .exe 分发到另一台机器,因为该 exe 似乎包含对生成 .exe 的机器上的绝对路径的引用。我还必须直接包含 vcruntime140.dll,因为 "include_msvcr": True 没有复制该文件。
设置
- 赢10
- Python 3.7.2
- cx_freeze 6.0
- 没有 virtualenv(不过好像没关系,我用 venv 试过了)
类似问题
之前有人以类似的形式提出过这个问题,但没有答案:cx_Freeze copies path
错误日志
在启动脚本时,出现以下错误(无法从窗口复制/粘贴,所以我分享了一张图片)。您可以看到对绝对路径 C:\Program Files (x86)\Python.... 的引用,该路径显然不存在于另一台机器上。
冻结脚本
from os.path import dirname
from cx_Freeze import setup, Executable
from config import settings
import os.path
import sys
import glob
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
DEPENDENCY_DIR = os.path.join(os.getcwd(), 'dependencies')
os.environ['TCL_LIBRARY'] = os.path.join(DEPENDENCY_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(DEPENDENCY_DIR, 'tcl', 'tk8.6')
packages = ["sepa", "datev", "atexit", "shiboken2", "PySide2"]
includes = []
excludes = ["Pyside2.Qt5WebEngineCore.dll"]
includefiles = ['qt', 'settings', 'config', os.path.join(DEPENDENCY_DIR, 'DLLs', 'tk86t.dll'),
os.path.join(DEPENDENCY_DIR, 'DLLs', 'tcl86t.dll'), os.path.join(DEPENDENCY_DIR, 'DLLs', 'vcruntime140.dll')]
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": packages,
"excludes": excludes,
"includes": includes,
"include_files": includefiles,
"optimize": 2,
"include_msvcr": True}
# 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="sepa_converter",
version=settings.version,
description="Programm zum Konvertiern von SEPA Dateien zum importieren in Buchhaltungsprogramme",
options={"build_exe": build_exe_options},
executables=[Executable("export_gui.py", base=base)])
#Debug DLLs von Pyside2 löschen
tmp = glob.glob("build/*/Pyside2/*d.dll")
for i in tmp:
os.remove(i)
tmp = glob.glob("build/*/Pyside2/*/*/*d.dll")
for i in tmp:
os.remove(i)
filelist = ['Qt5WebEngineCore.dll', 'icudt54.dll', 'opengl32sw.dll', 'Qt5Designer.dll', 'd3dcompiler_47.dll', 'Qt5Quick.dll']
for f in filelist:
for i in glob.glob("build/*/Pyside2/%s" % f):
os.remove(i)
【问题讨论】:
-
我也有同样的问题。
-
另一种解决方案:切换到 pyinstaller。似乎不那么麻烦了。
标签: python python-3.x cx-freeze