AssertionError when using PyInstaller. Fixed when following line is commented in modulegraph.py: assert prev_insts[-2].opname == 'LOAD_CONST'

47 views
Skip to first unread message

epri

unread,
Sep 1, 2022, 3:46:03 AM9/1/22
to PyInstaller
Wasn't sure whether or not to make this an issue so posting this here first.

PyInstaller version: 4.10
Version of Python: 3.6.8
Platform: Windows 10
Python installed from: python.org
Didn't try on another platform.
Will try development version if necessary.

Clean installation.
Ran program from command window
Used --onedir mode

Error:
\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2771, in _scan_bytecode
    assert prev_insts[-2].opname == 'LOAD_CONST'
AssertionError

Command line used: pyinstaller -F --clean --paths {paths --collect-all {name1} --collect-all {name2} script.py

The problem arises when using .pyc files for the modules in name1 and name2.
The problem does not occur when I comment out this line in modulegraph.py.
  • When I run pyinstaller without line 2764 (linked above), everything runs to completion and the executable generated works as intended.
I've been trying to look through previous commits to try and understand the reason for the assert statement and why it is necessary. Could it perhaps no longer be necessary?

The prev_insts[-2].opname variable is equal to EXTENDED_ARG thus causing the assert statement to fail.

There's been a few issues before related to extend_arg but not my exact problem as well as commits.
  1. Link
  2. Link
  3. And this link seems to be the commit for the first variation of the LOAD_CONST assert but it's not clear to me why it's there.
Based on what I found in PyInstaller's current bytecode.py, it does seem like this line may need to be expanded on:

The biggest clarity killer here is the ``EXTENDED_ARG`` opcode which can appear almost anywhere and therefore needs to be tiptoed around at every step. If this code needs to expand significantly, I would recommend an upgrade to a regex-based grammar parsing library such as Reparse. This way, little steps like unpacking ``EXTENDED_ARGS`` can be defined once then simply referenced forming a nice hierarchy rather than copied everywhere its needed.

Could you please provide some information about why this type of opcode requires an exception to be thrown and why PyInstaller works when the assertion is removed? Or just confirm with me whether or not it is safe for me to continue on with the line removed? Or even just a way to avoid running into this exception?

Reference to extended_arg from dis.py.

Thank you,

Eduardo

Jasper Harrison

unread,
Sep 1, 2022, 5:50:54 AM9/1/22
to pyins...@googlegroups.com
Eduardo

Please open a GitHub issue for this and mention me on it (@Legorooj).

Thanks,

Jasper Harrison, aka Legorooj
Core Developer on PyInstaller






-------- Original Message --------
--
You received this message because you are subscribed to the Google Groups "PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyinstaller...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyinstaller/6a5e44bd-ba26-433e-9048-22cea77326c9n%40googlegroups.com.
publickey - EmailAddress(s=legorooj@protonmail.com) - 0x164CF234.asc
signature.asc
Reply all
Reply to author
Forward
0 new messages