question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PyInstaller bundled app: Failing to get source code with exceptions

See original GitHub issue

Hey @Delgan,

I’m not too sure if this is a loguru or PyInstaller issue, but I figured I’d start here.

I’m still working on that app from my previous tickets and am running into an issue when it is bundled. When an exception occurs within the app while bundled (i.e. running from EXE), I am not seeing any source code being recorded by loguru from the exception. I tried this in a fresh environment (conda) with only loguru 0.5.3 and pyinstaller 4.0 the installed 3rd party libraries and got the same thing. I tried a different app with just a single, tiny file in both the original and new environment and still got the issue.

Here is an example output from the other application

2020-11-12 14:23:31.082 | INFO     | __main__:main:5 - Here is a message
2020-11-12 14:23:31.084 | ERROR    | __main__:<module>:10 - An error has been caught in function '<module>', process 'MainProcess' (8008), thread 'MainThread' (2504):
Traceback (most recent call last):

> File "main.py", line 10, in <module>

  File "main.py", line 7, in main

ValueError: Test error

As you can see, this is the default configuration for loguru. Anyways, here is the source code:

from loguru import logger

@logger.catch
def main():
    logger.info("Here is a message")

    raise ValueError("Test error")

if __name__ == "__main__":
    main()

Put that into a file named main.py and then run the following command with pyinstaller: pyinstaller main.py

Then run the bundled exe and it should produce the issue.

Let me know if there is anything else I can provide. Jules

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Delgancommented, Jan 4, 2022

@zhfkt Unfortunately I’m not aware of any solution without bundling data. As far as I know, the Python exception formatter needs the source file to retrieve and display the code lines.

1reaction
Delgancommented, Nov 13, 2020

Hello.

This looks very similar to this issue: #250 Can you confirm that this is the same problem?

It seems you need to the add the source code to the bundled application using --add-data=main.py;..

Read more comments on GitHub >

github_iconTop Results From Across the Web

When Things Go Wrong — PyInstaller 5.7.0 documentation
It may happen that when you attempt to bundle your app either PyInstaller itself, or your bundled app, terminates with a Python traceback....
Read more >
Inspect fails to retrieve source code inside frozen app (.py files ...
Description of the issue I'm trying to use inspect.getsource( ), e.g. inspect.getsource(datetime.date) in a frozen application.
Read more >
Bundling data files with PyInstaller (--onefile) - python
When I run my app, I get an error Failed to execute script foo (if foo.py is the main file). To troubleshoot this,...
Read more >
PyInstaller Documentation - Read the Docs
A quick summary of the GPL license exceptions: • You may use PyInstaller to bundle commercial applications out of your source code. •...
Read more >
When Things Go Wrong — PyArmor 7.6.0 documentation
Then set the right source code encoding in the scripts, first run the plain ... If you are using command pack, make sure...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found