use*_*007 6 python pyinstaller raspberry-pi raspbian
我想将 myscript.py 转换为可执行文件。我正在使用树莓派(raspbian)和 python 2.7。
我发出以下命令
sudo pip install PyInstaller
sudo pyinstaller myscript.py
Run Code Online (Sandbox Code Playgroud)
经过一些处理后,它提供了一个错误
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.
Run Code Online (Sandbox Code Playgroud)
我去网上构建编译器,但无法理解这个过程。我怎么能解决这个问题?
经过几个小时的搜索,我得到了这个工作。答案很简单,但它分布在多个 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
Run Code Online (Sandbox Code Playgroud)
在这里你应该看到Linux-32bit-arm它的内部run和run_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
Run Code Online (Sandbox Code Playgroud)
如果您看到以上内容,那么到目前为止您还不错。但是,如果您看到类似 的内容ELF 32-bit LSB executable, Intel 80386,那就错了。
3. 复制引导加载程序
如果您pip在内部安装了 PyInstaller venv,请执行以下操作
# 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/
Run Code Online (Sandbox Code Playgroud)
如果你用 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
Run Code Online (Sandbox Code Playgroud)
问题
SystemError: objcopy Failure: objcopy: Unable to recognise the format of the input file `$FILE`
Run Code Online (Sandbox Code Playgroud)
查看
`file dist/$FILE`
Run Code Online (Sandbox Code Playgroud)
如果它没有显示ELF 32-bit LSB executable, ARM [...],而是显示 Intel 或 x86,则 PyInstaller 会尝试使用不正确的引导加载程序。如果您执行了上述所有步骤,请尝试将 重命名Linux-32bit-arm为 just Linux-32bit。这似乎对这个用户有用
问题
gcc not found
Run Code Online (Sandbox Code Playgroud)
解决方案
sudo apt-get install build-essential
Run Code Online (Sandbox Code Playgroud)
怀疑引导加载程序的编译路径对于您的平台来说是错误的
可以按照论坛中提到的那样执行此操作
cd /usr/local/lib/python2.7/dist-packages/PyInstaller/bootloader
sudo mv Linux-32bit Linux-32bit-arm
Run Code Online (Sandbox Code Playgroud)
对于 RPI,您需要获取引导加载程序...您可以将 pyinstaller v3.1.1克隆到您的 rpi 中同样的事情,在构建 pyinstaller 后更改您的arm平台的目录名称
cd /path/to/pyinstaller/PyInstaller/bootloader
cp -R Linux-32bit Linux-32bit-arm
Run Code Online (Sandbox Code Playgroud)