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.

Sourcecode not visible when using PyInstaller

See original GitHub issue

Important Details

How are you running Sentry? Frozen python app created with PyInstaller

On-Premise w/ Docker, version x.y.z

Saas (sentry.io)

Other, version x.y.z, [briefly describe your environment]

Description

When my app is frozen with pyinstaller, the error context lines are not captured.

Added a couple print statements in sentry_sdk/utils.py:


def get_lines_from_file(
    filename,  # type: str
    lineno,  # type: int
    loader=None,  # type: Optional[Any]
    module=None,  # type: Optional[str]
):
    # type: (...) -> Tuple[List[Annotated[str]], Optional[Annotated[str]], List[Annotated[str]]]
    context_lines = 5
    source = None
    if loader is not None and hasattr(loader, "get_source"):
        try:
            source_str = loader.get_source(module)  # type: Optional[str]
        except (ImportError, IOError):
            source_str = None
        if source_str is not None:
            source = source_str.splitlines()

    print(f'filename: {filename}, module: {module}')
    print(f'source is None: {source is None}')
    if source is None:
        try:
            source = linecache.getlines(filename)
            print(f'source: {source}')
        except (OSError, IOError):
            return [], None, []

and at the end of sentry_sdk\client.py at line 216 in _prepare_event, i just printed print(event['exception']) to see the final event exception passed out. (trimmed some extra non imporant stuff off this)

App not frozen (working):

filename: Y:\OneDrive\Python\SMS\smseventlog\gui\gui.py, module: smseventlog.gui.gui
source is None: False

{'filename': 'smseventlog\\gui\\gui.py', 
'abs_path': 'Y:\\OneDrive\\Python\\SMS\\smseventlog\\gui\\gui.py', 
'function': 'test_error', 
'module': 'smseventlog.gui.gui', 
'lineno': 257, 
'pre_context': ['', '    def test_error(self):', '        a = 5', '        b = 6', ''], 
'context_line': '        return a / 0', 
'post_context': ['', '    def create_actions(self):', '        # Menu/shortcuts', '        t = self.active_table_widget', ''], 
'vars': {'self': '<smseventlog.gui.gui.MainWindow object at 0x000002CD9D0DFAF0>', 'a': '5', 'b': '6'}, 
'in_app': True}]}

App frozen (not working):

filename: smseventlog\gui\gui.py, module: smseventlog.gui.gui
source is None: True
source: []

 {'filename': 'smseventlog\\gui\\gui.py', 
'abs_path': 'C:\\Users\\Jayme\\Documents\\smseventlog\\dist\\smseventlog_win\\smseventlog\\gui\\gui.py', 
'function': 'test_error', 
'module': 'smseventlog.gui.gui', 
'lineno': 257,
 'pre_context': [], 
'context_line': None, 
'post_context': [], 
'vars': {'self': '<smseventlog.gui.gui.MainWindow object at 0x0000022638C4A280>', 'a': '5', 'b': '6'}, 
'in_app': True}]}}]}

the difference seems to be that in the non frozen app, the full filename is recognized Y:\OneDrive\Python\SMS\smseventlog\gui\gui.py, while in the frozen app its only recoginzed as smseventlog\gui\gui.py and the module can’t be propery read to find the lines specified in the traceback.

Steps to Reproduce

What you expected to happen

Pre and post context should be captured, even in a frozen app.

Possible Solution

[If you have an idea on how this could be solved include that detail here.]

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
jaymegordocommented, Oct 9, 2020

Any progress on this one? would be super helpful to have working thx!!! 😃

1reaction
untitakercommented, Sep 2, 2020

That’s a known issue in the Python SDK. Moving there.

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - Pyinstaller and Ply IOError: source code not available
My script runs fine normally but throws IOerror when i try to build with pyinstaller, my modules (including ply.lex) seem to be included...
Read more >
When Things Go Wrong — PyInstaller 5.7.0 documentation
If Analysis thinks it has found all the imports, but the app fails with an import error, the problem is a hidden import;...
Read more >
Problems with Pyinstaller & and Common Fixes - YouTube
uite error prone, and many people have run into alot of constant errors and problems while using Pyinstaller. This Video was created for...
Read more >
PyInstaller Documentation - Read the Docs
py file is located, then build your app with the following command: pyinstaller your_program.py. Your bundled application should now be available in the...
Read more >
Package Data Files to pyinstaller Binaries
This is because your pyinstaller executable looks for data files in a temp directory _MEIXXXX where XXXX is a random number. You need...
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