python-build-standalone icon indicating copy to clipboard operation
python-build-standalone copied to clipboard

Linux builds break PyInstaller

Open alexdelorenzo opened this issue 1 year ago • 3 comments

I installed the portable Python 3.12.3 build like so:

$ rye toolchain fetch [email protected]
$ rye init
$ rye pin [email protected]

Rye downloads and uses the IndyGreg Portable Python builds

Basic case to reproduce

Create the base case file:

# main.py
print("hello world")

Run PyInstaller on the file:

$ python -m pip install PyInstaller
$ python -m PyInstaller --onefile main.py

Then run the compiled binary:

$ dist/main
[1475051] Module object for struct is NULL!
Traceback (most recent call last):
  File "struct.py", line 13, in <module>
ModuleNotFoundError: No module named '_struct'

The expected result, using the system Python, is:

$ dist/main
hello world

alexdelorenzo avatar Jul 10 '24 05:07 alexdelorenzo

Thanks for the report. Vaguely looks this module should be present, e.g., https://github.com/indygreg/python-build-standalone/commit/60d4e65147964c0e02fa402bc298c2f5e0ae341c. I'm not sure what's going on — I'm not particularly familiar with how PyInstaller works.

zanieb avatar Jul 10 '24 06:07 zanieb

No problem. I can try to dig deeper when I have some time.

I can confirm that the Portable Python builds for x86_64 macOS and Windows don't have this problem, they work fine with PyInstaller. Seems to just be the Linux (x86_64, at least) builds.

alexdelorenzo avatar Jul 10 '24 21:07 alexdelorenzo

Tried on a fresh Ubuntu 24.04 VM using the following main.py:

import multiprocessing
print("hello world")

Then followed the steps in the OP to compile dist/main:

$ dist/main
Traceback (most recent call last):
  File "PyInstaller/hooks/rthooks/pyi_rth_multiprocessing.py", line 107, in <module>
  File "PyInstaller/hooks/rthooks/pyi_rth_multiprocessing.py", line 95, in _pyi_rthook
  File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
  File "multiprocessing/popen_forkserver.py", line 7, in <module>
  File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
  File "multiprocessing/forkserver.py", line 11, in <module>
  File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
  File "multiprocessing/connection.py", line 22, in <module>
ModuleNotFoundError: No module named '_multiprocessing'
[13284] Failed to execute script 'pyi_rth_multiprocessing' due to unhandled exception!

Looks like C modules from the standard library are tripping up PyInstaller on Linux with the Portable Python builds, it's not just _struct that's the problem.

alexdelorenzo avatar Jul 19 '24 22:07 alexdelorenzo

This was fixed on PyInstaller's end with https://github.com/pyinstaller/pyinstaller/pull/8850. Thanks for your time, @zanieb!

alexdelorenzo avatar Oct 29 '24 02:10 alexdelorenzo