Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyinstaller -w --onedir main.py opens and closes immediately #6992

Closed
kanewi11 opened this issue Jul 28, 2022 · 9 comments
Closed

pyinstaller -w --onedir main.py opens and closes immediately #6992

kanewi11 opened this issue Jul 28, 2022 · 9 comments

Comments

@kanewi11
Copy link

kanewi11 commented Jul 28, 2022

pyinstaller -w --onedir main.py on macOS opens and closes immediately, the file main.app/Contents/MacOS/main opens, what to do?

im use tkinter

@kanewi11 kanewi11 added the triage Please triage and relabel this issue label Jul 28, 2022
@rokm
Copy link
Member

rokm commented Jul 28, 2022

Is main.py a GUI program?

@kanewi11
Copy link
Author

Is main.py a GUI program?

Tkinter yes

@rokm
Copy link
Member

rokm commented Jul 28, 2022

Any chance we can see the minimal reproducer, then?

@rokm
Copy link
Member

rokm commented Jul 28, 2022

Or, you can try wrapping your whole entry-point script into a try/catch block, and write the exception information to a fixed location (e.g., your home directory), like suggested here: #5154 (comment).

So if your program is crashing with uncaught exception, you'll know what's happening.

@rokm
Copy link
Member

rokm commented Jul 28, 2022

Ah, I meant source code, not the binary.

@kanewi11
Copy link
Author

error.log clear

@kanewi11
Copy link
Author

Ah, I meant source code, not the binary.

https://drive.google.com/drive/folders/1ZBkli3uoGJh-ByVIIIazojrwM6rZDCTn?usp=sharing

@rokm
Copy link
Member

rokm commented Jul 28, 2022

service/parser.py, line 15:

proxies = open(f'{os.getcwd()}/proxy.txt').read().split('\n')

This assumes that proxy.txt is in current working directory. Which is definitely not the case when you launch an .app bundle. I suppose running main.app/Contents/MacOS/main only because you are running it from the source directory...

That f'{os.getcwd()}/proxy.txt' should be replaced with os.path.join(os.path.dirname(__file__), '..', 'proxy.txt') or with os.path.join(sys._MEIPASS, 'proxy.txt') under if getattr(sys, 'frozen', False): check for frozen application codepath.

EDIT: you actually need to use os.path.join(sys._MEIPASS, 'proxy.txt') in frozen codepath, because service directory does not exist in the frozen application. But you could move the proxy.txt into service, and then reference it via os.path.join(os.path.dirname(__file__), 'proxy.txt') in both frozen and unfrozen codepath. But you'd need to ensure it is also collected into service subdirectory instead of the top-level frozen application directory (--add-data path/to/service/proxy.txt:service instead of --add-data path/to/service/proxy.txt:.).


By the way, with exception catching I meant the whole entry-point script:

try:
    from service.parser import app

    if __name__ == '__main__':
        app.mainloop()
except Exception as e:
    import traceback
    with open('/Users/username/error.log', 'w') as fp:
        fp.write(f"ERROR {e}\n\n")
        traceback.print_exc(file=fp)

This gives:

ERROR [Errno 2] No such file or directory: '//proxy.txt'

Traceback (most recent call last):
  File "main.py", line 2, in <module>
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstaller/loader/pyimod03_importers.py", line 495, in exec_module
  File "service/parser.py", line 15, in <module>
FileNotFoundError: [Errno 2] No such file or directory: '//proxy.txt'

@bwoodsend bwoodsend added solution:invalid and removed triage Please triage and relabel this issue labels Jul 28, 2022
@bwoodsend bwoodsend closed this as not planned Won't fix, can't repro, duplicate, stale Jul 28, 2022
@kanewi11
Copy link
Author

I did this before, but I forgot to update the Google disk file. The problem was in the loguru, you had to put the file in there too, otherwise he couldn't access it, thank you very much and sorry for the trouble 😊

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants