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

Marshal error passing modulegraph.Alias() to find_binary_dependencies() #7515

Closed
bwoodsend opened this issue Mar 24, 2023 · 2 comments · Fixed by #7517
Closed

Marshal error passing modulegraph.Alias() to find_binary_dependencies() #7515

bwoodsend opened this issue Mar 24, 2023 · 2 comments · Fixed by #7517
Labels
triage Please triage and relabel this issue

Comments

@bwoodsend
Copy link
Member

Description of the issue

Modulegraph has an internal Alias() class which simply inherits from str() to label known module name compatibility aliases/redirects. If one of these Alias instances find their way anywhere near PyInstaller.isolated then a build error occurs because marshal refuses to serialize them.

Context information (for bug reports)

  • Output of pyinstaller --version: Anything >= 5.4
  • Version of Python: 3.11
  • Platform: Windows only
  • How you installed Python: python.org

A minimal example program which shows the error

Simply try to build:

import six.moves.tkinter

Stacktrace / full error message

$ python -m PyInstaller test.py
2874 INFO: PyInstaller: 5.9.0
2874 INFO: Python: 3.11.0
2905 INFO: Platform: Windows-10-10.0.19044-SP0
2905 INFO: wrote C:\Users\scsbuild\PySolFC\test.spec
2905 INFO: UPX is not available.
2921 INFO: Extending PYTHONPATH with paths
['C:\\Users\\scsbuild\\PySolFC']
pygame 2.3.0 (SDL 2.24.2, Python 3.11.0)
Hello from the pygame community. https://www.pygame.org/contribute.html
3515 INFO: checking Analysis
3515 INFO: Building Analysis because Analysis-00.toc is non existent
3515 INFO: Initializing module dependency graph...
3515 INFO: Caching module graph hooks...
3546 INFO: Analyzing base_library.zip ...
6506 INFO: Loading module hook 'hook-heapq.py' from 'C:\\Users\\scsbuild\\PySolFC\\env\\Lib\\site-packages\\PyInstaller\\hooks'...
6641 INFO: Loading module hook 'hook-encodings.py' from 'C:\\Users\\scsbuild\\PySolFC\\env\\Lib\\site-packages\\PyInstaller\\hooks'...
8857 INFO: Loading module hook 'hook-pickle.py' from 'C:\\Users\\scsbuild\\PySolFC\\env\\Lib\\site-packages\\PyInstaller\\hooks'...
11094 INFO: Caching module dependency graph...
11245 INFO: running Analysis Analysis-00.toc
11249 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by C:\Python\python.exe
11450 INFO: Analyzing C:\Users\scsbuild\PySolFC\test.py
11483 INFO: Processing pre-safe import module hook six.moves from 'C:\\Users\\scsbuild\\PySolFC\\env\\Lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-six.moves.py'.
11773 INFO: Processing module hooks...
11773 INFO: Loading module hook 'hook-_tkinter.py' from 'C:\\Users\\scsbuild\\PySolFC\\env\\Lib\\site-packages\\PyInstaller\\hooks'...
11780 INFO: checking Tree
11827 INFO: checking Tree
11843 INFO: checking Tree
11859 INFO: Looking for ctypes DLLs
11859 INFO: Analyzing run-time hooks ...
11874 INFO: Including run-time hook 'C:\\Users\\scsbuild\\PySolFC\\env\\Lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_inspect.py'
11874 INFO: Including run-time hook 'C:\\Users\\scsbuild\\PySolFC\\env\\Lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth__tkinter.py'
11887 INFO: Looking for dynamic libraries
Traceback (most recent call last):
  File "C:\Users\scsbuild\PySolFC\env\Lib\site-packages\PyInstaller\isolated\_child.py", line 96, in <module>
    while run_next_command(read_fh, write_fh):
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\scsbuild\PySolFC\env\Lib\site-packages\PyInstaller\isolated\_child.py", line 51, in run_next_command
    args = loads(b64decode(read_fh.readline().strip()))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
EOFError: EOF read where object expectedTraceback (most recent call last):
  File "C:\Python\Lib\pdb.py", line 1768, in main
    pdb._run(target)
  File "C:\Python\Lib\pdb.py", line 1646, in _run
    self.run(target.code)
  File "C:\Python\Lib\bdb.py", line 597, in run
    exec(cmd, globals, locals)
  File "C:\Users\scsbuild\PySolFC\env\Lib\site-packages\PyInstaller\__main__.py", line 198, in <module>
    run()
  File "C:\Users\scsbuild\PySolFC\env\Lib\site-packages\PyInstaller\__main__.py", line 180, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "C:\Users\scsbuild\PySolFC\env\Lib\site-packages\PyInstaller\__main__.py", line 61, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "C:\Users\scsbuild\PySolFC\env\Lib\site-packages\PyInstaller\building\build_main.py", line 983, in main
    build(specfile, distpath, workpath, clean_build)
  File "C:\Users\scsbuild\PySolFC\env\Lib\site-packages\PyInstaller\building\build_main.py", line 905, in build
    exec(code, spec_namespace)
  File "C:\Users\scsbuild\PySolFC\test.spec", line 7, in <module>
    a = Analysis(
        ^^^^^^^^^
  File "C:\Users\scsbuild\PySolFC\env\Lib\site-packages\PyInstaller\building\build_main.py", line 414, in __init__
    self.__postinit__()
  File "C:\Users\scsbuild\PySolFC\env\Lib\site-packages\PyInstaller\building\datastruct.py", line 173, in __postinit__
    self.assemble()
  File "C:\Users\scsbuild\PySolFC\env\Lib\site-packages\PyInstaller\building\build_main.py", line 701, in assemble
    isolated.call(find_binary_dependencies, list(self.binaries), self.binding_redirects, collected_packages)
  File "C:\Users\scsbuild\PySolFC\env\Lib\site-packages\PyInstaller\isolated\_parent.py", line 372, in call
    return isolated.call(function, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\scsbuild\PySolFC\env\Lib\site-packages\PyInstaller\isolated\_parent.py", line 289, in call
    self._send(function.__code__, function.__defaults__, function.__kwdefaults__, args, kwargs)
  File "C:\Users\scsbuild\PySolFC\env\Lib\site-packages\PyInstaller\isolated\_parent.py", line 306, in _send
    self._write_handle.write(b64encode(dumps(object)))
                                       ^^^^^^^^^^^^^
ValueError: unmarshallable object

PDB-ing into that exception:

(Pdb) object[2]
['importlib', 'importlib.metadata', 'importlib.resources', 'logging', 'email', 'encodings', 'collections', 'http', 'urllib', 're', 'tkinter']
(Pdb) object[2][-1]
'tkinter'
(Pdb) type(object[2][-1])
<class 'PyInstaller.lib.modulegraph.modulegraph.Alias'>
@bwoodsend bwoodsend added the triage Please triage and relabel this issue label Mar 24, 2023
@bwoodsend bwoodsend changed the title Marshal error passing modulegraph.Alias() to Marshal error passing modulegraph.Alias() to find_binary_dependencies() Mar 24, 2023
@bwoodsend
Copy link
Member Author

Maybe just a dumb collected_packages = [str(i) for i in collected_packages] in here?

@rokm
Copy link
Member

rokm commented Mar 24, 2023

Maybe just a dumb collected_packages = [str(i) for i in collected_packages] in here?

Sounds good. But we should probably do a str(node.identifier) here:

def get_collected_packages(self) -> list:
"""
Return the list of collected python packages.
"""
return [
node.identifier for node in self.iter_graph(start=self._top_script_node) if type(node).__name__ == 'Package'
]

(or perhaps even ensure that node.identifier is always a proper str, although that's probably wasted effort at this point).

rokm added a commit to rokm/pyinstaller that referenced this issue Mar 25, 2023
…rings

Explicitly convert `node.identifier` to plain `str` to avoid
later marshal errors when `node.identifier` happens to be
an instance of `modulegraph.Alias`.

Fixes pyinstaller#7515.
Legorooj pushed a commit that referenced this issue Mar 25, 2023
…rings (#7517)

Explicitly convert `node.identifier` to plain `str` to avoid
later marshal errors when `node.identifier` happens to be
an instance of `modulegraph.Alias`.

Fixes #7515.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
triage Please triage and relabel this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants