使用cx_freeze冻结后的绝对路径(Qt5 / PySide2 App)

问题描述 投票:3回答:1

问题:

我无法将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)
python python-3.x cx-freeze
1个回答
0
投票

降级为cx_freeze 5.1.1为我解决了该问题。

© www.soinside.com 2019 - 2024. All rights reserved.