作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我想将 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
和它里面的 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
如果你看到上面的内容,那么你到目前为止还不错。但是,如果您看到类似 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/
我是一名优秀的程序员,十分优秀!