gpt4 book ai didi

python - 使用 cx_freeze 卡住后的绝对路径(Qt5/PySide2 应用程序)

转载 作者:行者123 更新时间:2023-12-02 09:31:40 25 4
gpt4 key购买 nike

问题:

我无法将 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... 的引用,该绝对路径显然不存在于另一台计算机上。

cx_freeze error log

卡住脚本

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)

最佳答案

降级到 cx_freeze 5.1.1 解决了我的问题。

关于python - 使用 cx_freeze 卡住后的绝对路径(Qt5/PySide2 应用程序),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58287342/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com