mailbagit icon indicating copy to clipboard operation
mailbagit copied to clipboard

mailbagit-gui command not running on Windows

Open gwiedeman opened this issue 2 years ago • 3 comments

Describe the bug While #147 addressed most of the remaining GUI issues mentioned in #76, the mailbagit-gui command as defined as an entry point in setup.py does not fully run in Windows. It opens the GUI window and allows you to fill out the fields, but once you try and run it it returns:

c:\users\greg\appdata\local\programs\python\python37-32\python.exe: can't open file 'C:\Users\Greg\.virtualenvs\mailbag-_Z7D2G4R\Scripts\mailbagit-gui': [Errno 2] No such file or directory

This example is using a virtualenv managed by pipenv, but the same thing happens using the system python. There is a mailbagit-gui.exe file located in that directory and I think that's what's being called when you first run the mailbagit-gui command. If I just run C:\Users\gw234478\.virtualenvs\mailbag-wl96s53w\Scripts\mailbagit-gui it does load the GUI window (even outside of the virtualenv). I think its running python path/to/mailbagit-gui which tries and fails to run the exe.

There is also a mailbagit-gui-script.py file in the scripts directory that appears to run the exe? Running this directly also fails with the same result.

This does not happen on Ubuntu 20.04 so it appears to be limited to Windows. Looks like the entry_point for ubuntu is a Python script instead of an .exe, which explains why it runs fine with python mailbagit-gui but Windows does not. This makes me think its a Gooey bug not handling or supporting entry points on Windows because of this.

gui-error

To Reproduce Steps to reproduce the behavior:

  1. enter the command mailbagit-gui
  2. fill out the options in the GUI
  3. Click "Start"

Expected behavior After you click "Start" it should package the file(s) provided into a mailbag.

Environment (please complete the following information):

  • GUI or command line?: GUI
  • OS: Win10
  • Python version: multiple but using 3.9.12 right now.

Additional context Works fine from the mailbagit-gui.py script which just runs mailbagit.gui(). This is used to build the executable so that path works fine.

gwiedeman avatar May 02 '22 14:05 gwiedeman

Looks like this is Gooey issue #649.

gwiedeman avatar May 02 '22 14:05 gwiedeman

Looked this over and concur - don't think we can meaningfully fix this on our end, we'd need to fix it and submit upstream.

pobocks avatar May 10 '22 23:05 pobocks

Also ran into this problem. I've come up with a workaround and an idea for a permanent fix.

Workaround: In the module / function being executed by your script, insert something like this:

if not os.path.isfile(sys.argv[0]):
    exit(os.system(f"{sys.executable} -m <python module> {' '.join(sys.argv[1:]}"))

i.e. in your case this could be (not tested):

import sys
if gooeyCheck:

    @Gooey(richtext_controls=True)
    def gui():
        """hook for GUI mailbagit invocation"""
        if not os.path.isfile(sys.argv[0]):
            exit(os.system(f"{sys.executable} -m mailbagit.gui  {' '.join(sys.argv[1:]}"))
        args = mailbag_parser.parse_args()
        main(args)

Idea for permanent fix

  • check sys.argv[1] does not exist
  • if yes, execute the corresponding exe file instead of python {sys.argv[1]}

Unfortunately I don't have the time to implement this and create a PR in gooey at this time

dominikandreas avatar Oct 30 '22 19:10 dominikandreas