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

Har*_*per 8 python cx-freeze python-3.x

问题:

我无法将cx_freeze生成的.exe分发到另一台计算机,因为似乎exe包含对生成.exe的计算机上绝对路径的引用。我还必须直接包含vcruntime140.dll,因为"include_msvcr": True没有复制文件。

设定

  • 赢10
  • 的Python 3.7.2
  • cx_freeze 6.0
  • 没有virtualenv(虽然似乎没有关系,但我已经用venv尝试过)

类似问题

以前已经以类似的形式问过这个问题,但没有答案:cx_Freeze复制路径

错误记录

启动脚本时,出现以下错误(无法从窗口复制/粘贴,因此我共享图片)。您可以看到对绝对路径的引用,该引用C:\Program Files (x86)\Python....显然不在另一台计算机上。

cx_freeze错误日志

冻结脚本

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)
Run Code Online (Sandbox Code Playgroud)

Har*_*per 1

使其发挥作用的步骤:

  1. 安装Python 3.6 32 位。其他版本不适合我。32 位似乎对于 skript 的 Qt / Tk 部分很重要,3.6 对于 cx-freeze 5.1.1 很重要。
  2. 安装cx-freeze==5.1.1
  3. 构建.exe。