gpt4 book ai didi

python - pyinstaller 没有为树莓派预定义的编译器

转载 作者:太空狗 更新时间:2023-10-30 02:42:55 28 4
gpt4 key购买 nike

我想将 myscript.py 转换为可执行文件。我正在使用树莓派 (raspbian) 和 python 2.7。

我正在发出以下命令

sudo pip install PyInstaller
sudo pyinstaller myscript.py

经过一些处理后它提供了一个错误

Fatal error: PyInstaller does not include a pre-compiled bootloader for your
platform. See <http://pythonhosted.org/PyInstaller/#building-the-bootloader>
for more details and instructions how to build the bootloader.

我上网构建编译器,但无法理解该过程。我该如何解决这个问题?

最佳答案

完整教程

经过数小时的搜索,我成功了。答案很简单,但分布在多个 StackExchange 答案和 GitHub 问题中。我在本教程中将所有内容放在一起,因此我为下一个可怜的灵魂节省了一些时间。

要点

  • pip 使用不正确的架构发布 PyInstaller。您需要自己为 ARM (Raspberry Pi) 构建它。

循序渐进

<强>1。构建引导加载程序

git clone https://github.com/pyinstaller/pyinstaller 
# Alternatively download the zip from https://github.com/pyinstaller/pyinstaller/releases
cd pyinstaller/bootloader
python ./waf distclean all # or python3
cd ../PyInstaller/bootloader/
ls

在这里你应该看到 Linux-32bit-arm 和它里面的 runrun_d

<强>2。检查引导加载程序

file Linux-32bit-arm/run

run: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=a01c65d74d7d8b483800154dcdd4a5d2aad95d5b, stripped

如果你看到上面的内容,那么你到目前为止还不错。但是,如果您看到类似 ELF 32-bit LSB executable, Intel 80386 的内容,那就错了。

<强>3。复制引导加载程序

如果您在 venv 中使用 pip 安装了 PyInstaller,则执行此操作

# Replace ${CLONED_PYINSTALLER_PATH} with the path where you git cloned above
# Replace ${PATH_TO_YOUR_PROJECT} with the path to your project (where you have the venv)

cp -r ${CLONED_PYINSTALLER_PATH}/PyInstaller/bootloader/Linux-32bit-arm ${PATH_TO_YOUR_PROJECT}/venv/lib/python3.5/site-packages/PyInstaller/bootloader/

如果你安装了 apt-get,那么就这样做

# !!! Replace python3.5 with your version
cp -r ${CLONED_PYINSTALLER_PATH}/PyInstaller/bootloader/Linux-32bit-arm /usr/local/lib/python3.5/dist-packages/PyInstaller/bootloader

调试

问题

SystemError: objcopy Failure: objcopy: Unable to recognise the format of the input file `$FILE`

检查

`file dist/$FILE`

如果它没有说 ELF 32-bit LSB executable, ARM [...],而是说 Intel 或 x86,PyInstaller 会尝试使用不正确的引导加载程序。如果您执行了上述所有步骤,请尝试将 Linux-32bit-arm 重命名为 Linux-32bit。这似乎适用于 this user


问题

gcc not found

解决方案

sudo apt-get install build-essential

关于python - pyinstaller 没有为树莓派预定义的编译器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35057675/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com