3

I'm trying to pack a python tool I wrote into an exe file for use on Windows 10. As far as I know, the exe is built correctly. It loads and everything works if I run it from the command line.

However, if I try to run the tool from Explorer (double-clicking the icon), I get a "Failed to execute script" error. I've tried building it using the --debug switch, hoping that I could quickly catch any output before cmd closes, but it's just too fast.

The line I use to build the tool is:

pyinstaller.exe --onefile --debug --console --icon=C:\Users\Ross\Desktop\gtt\assets\icon.ico --hidden-import xlrd gtt.py

It worked perfectly before I began using the reportlab modules:

from reportlab.lib import colors
from reportlab.lib.enums import TA_CENTER
from reportlab.lib.pagesizes import letter, portrait
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import inch
from reportlab.platypus import SimpleDocTemplate, Table, TableStyle, Paragraph, Spacer

The command line gives absolutely no output regarding errors when I run it using the debug switch: Screenshot showing tool running in cmd

I've tried the following and nothing has worked.

  • --noupx
  • --onedir
  • --onefile

To sum it up, why would a PyInstaller exe file work when run from the command line, but not from the Windows GUI?

EDIT: The issue seems to be with PyQt4. I went back to a commit where I switch from tkinter to Qt and the issue is still there. The previous build, with tkinter, loads fine from the GUI.

1 Answer 1

1

I figured it out!

I had to convert the gui.ui file into a package.

  1. I created the package "gui," containing an empty __init__.py
  2. I ran pyuic4 gui.ui -o gui.pyto convert the gui.ui code into Python
  3. I moved both gui.ui and gui.py files into the gui directory
  4. In my main program code, I imported the module: from gui.gui import *

Hope that helps anyone else!

Not the answer you're looking for? Browse other questions tagged or ask your own question.