Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Absolute paths after freezing with cx_freeze (Qt5 / PySide2 App)

Problem:

I cannot distribute a cx_freeze generated .exe to another machine, because it seems the exe contains references to absolute paths on the machine that generated the .exe. I also had to include vcruntime140.dll direktly, because "include_msvcr": True didnt copy the file.

Setup

  • Win 10
  • Python 3.7.2
  • cx_freeze 6.0
  • NO virtualenv (doesnt seem to matter though, i have tried it with venv)

Similar questions

This question has been asked before in a similar form, but does not have an answer: cx_Freeze copies path

Error Log

On starting the script, the following errors show up (cannot copy/paste from the window, so i share a picture). You can see the references to an absolute path C:\Program Files (x86)\Python.... that obviously is not present on another machine.

cx_freeze error log

freeze script

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)
like image 753
Harper Avatar asked Oct 08 '19 13:10

Harper


2 Answers

Downgrading to cx_freeze 5.1.1 resolved the issue for me.

like image 139
Lawrence Avatar answered Nov 19 '22 09:11

Lawrence


Steps to make it work:

  1. Install Python 3.6 32-Bit. Other Versions did not work for me. 32-Bit seems to be important for the Qt / Tk parts of the skript, 3.6 was important for cx-freeze 5.1.1.
  2. Install cx-freeze==5.1.1
  3. Build .exe.
like image 1
Harper Avatar answered Nov 19 '22 11:11

Harper