Use Pyinstaller inside crossenv for cross packaging
Pyinstaller is a packaging tool for python applications. https://pyinstaller.readthedocs.io/en/stable/ But it's not a cross compiler. Therefore, applications packaged on Linux x86 will only run on Linux x86. Applications packaged on Arm, will only run on Arm.
I'm looking for a way to package Arm applications on my Ubuntu machine. Would it somehow be possible using Pyinstaller inside crossenv?
What I've already tried is the following:
Downloaded python 3.7 source. Build for Ubuntu and cross build for Arm.
Run cross env bin/python3.7-ubuntu -m crossenv usr/bin/python3.7-arm venv
(cross) user@computer1 $ python -m sysconfig
Platform: "linux-arm"
Python version: "3.7"
Current installation scheme: "posix_prefix"
[...]
BUILD_GNU_TYPE = "x86_64-pc-linux-gnu"
CC = "arm-omap3-linux-gnueabihf-gcc"
And then I tried:
(cross) user@computer1 $ pip install pyinstaller
Collecting pyinstaller
Using cached https://files.pythonhosted.org/packages/7f/6b/688fceb8f1fafeb028de72ad47c5b1377be9f74a75801802f1463e451b22/pyinstaller-4.8.tar.gz
Installing build dependencies ... done
Requirement already satisfied: setuptools in ./venv/cross/lib/python3.7/site-packages (from pyinstaller) (39.0.1)
Collecting altgraph (from pyinstaller)
Using cached https://files.pythonhosted.org/packages/84/3f/1a5c9bef54cac9bf41edd6f4aaf61cd52ed578e10ccc607e0278012cb4a5/altgraph-0.17.2-py2.py3-none-any.whl
Collecting pyinstaller-hooks-contrib>=2020.6 (from pyinstaller)
Using cached https://files.pythonhosted.org/packages/a5/51/aca8508043b9564620bdd96adbc824b8d84537afcfb92ff806ea119ee176/pyinstaller_hooks_contrib-2022.0-py2.py3-none-any.whl
Collecting importlib-metadata (from pyinstaller)
Using cached https://files.pythonhosted.org/packages/58/fd/f82049e9b21773188a72bd1bc53530b900392808f8b823e4c778e7c035f0/importlib_metadata-4.10.1-py3-none-any.whl
Collecting zipp>=0.5 (from importlib-metadata->pyinstaller)
Using cached https://files.pythonhosted.org/packages/52/c5/df7953fe6065185af5956265e3b16f13c2826c2b1ba23d43154f3af453bc/zipp-3.7.0-py3-none-any.whl
Collecting typing-extensions>=3.6.4; python_version < "3.8" (from importlib-metadata->pyinstaller)
Using cached https://files.pythonhosted.org/packages/05/e4/baf0031e39cf545f0c9edd5b1a2ea12609b7fcba2d58e118b11753d68cf0/typing_extensions-4.0.1-py3-none-any.whl
Installing collected packages: altgraph, pyinstaller-hooks-contrib, zipp, typing-extensions, importlib-metadata, pyinstaller
Running setup.py install for pyinstaller ... error
Complete output from command /home/.../projects/python-sources-build-test/Python-3.7.0-arm/destination/venv/cross/bin/python3.7 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-pxafki_6/pyinstaller/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-0vdiepu3/install-record.txt --single-version-externally-managed --compile --install-headers /home/.../projects/python-sources-build-test/Python-3.7.0-arm/destination/venv/cross/include/site/python3.7/pyinstaller:
running install
/tmp/pip-build-env-r7ohu9gu/lib/python3.7/site-packages/setuptools/command/install.py:37: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
setuptools.SetuptoolsDeprecationWarning,
running build
running build_bootloader
No precompiled bootloader found or compile forced. Trying to compile the bootloader for you ...
Setting top to : /tmp/pip-install-pxafki_6/pyinstaller/bootloader
Setting out to : /tmp/pip-install-pxafki_6/pyinstaller/bootloader/build
Python Version : 3.7.0 (default, Jan 31 2022, 17:07:08) [GCC 9.3.0]
Checking for 'gcc' (C compiler) : /usr/bin/gcc
Checking size of pointer : not found
Couldn't determine pointer size, only 32 or 64 bit are supported. Please use `--target-arch' to set the pointer size.
(complete log in /tmp/pip-install-pxafki_6/pyinstaller/bootloader/build/config.log)
ERROR: Failed compiling the bootloader. Please compile manually and rerun setup.py
----------------------------------------
Command "/home/.../projects/python-sources-build-test/Python-3.7.0-arm/destination/venv/cross/bin/python3.7 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-pxafki_6/pyinstaller/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-0vdiepu3/install-record.txt --single-version-externally-managed --compile --install-headers /home/.../projects/python-sources-build-test/Python-3.7.0-arm/destination/venv/cross/include/site/python3.7/pyinstaller" failed with error code 1 in /tmp/pip-install-pxafki_6/pyinstaller/
You are using pip version 10.0.1, however version 22.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Any ideas would be very appreciated!
That's a very interesting idea. I'm not sure I know PyInstaller well enough to be of much help, unfortunately.
Looking at that message, it looks like it couldn't figure out the pointer size. I'm curious about that, actually, because I would expect that sort of thing to work, generally. In the mean time, maybe you could use --install-option to pass the --target-arch option it suggests. I don't know what target architecture names are valid for PyInstaller.
pip install --install-option='--target-arch=???` pyinstaller