OpenWrt MT7621使用pyinstaller打包失败解决办法
来源:互联网 发布:淘宝主营率是什么意思 编辑:程序博客网 时间:2024/06/07 10:45
前段时间移植一个python项目到OpenWrt,掉了不少坑,总结一下希望帮到有需要的人,来看打包问题:
0x01
在OpenWrt 使用pip直接安装了pyinstaller,打包过程中出现文件缺失、文件错误的问题:
从githut/pyinstaller得知linux环境下使用pyinstaller需要ldd、objcopy、objdump支持,openwrt安装gcc即可自动安装binutils:
opkg update opkg install gcc
github pyinstaller:https://github.com/pyinstaller/pyinstaller
0x02
继续打包,继续报错,错误信息如下:
root@mux:~/huanyun_daemon# pyinstaller hy_daemon.py2230 INFO: PyInstaller: 3.2.12232 INFO: Python: 2.7.92240 INFO: Platform: Linux-3.18.29-mips-with-glibc2.02244 INFO: wrote /root/huanyun_daemon/hy_daemon.spec2278 INFO: UPX is not available.2294 INFO: Extending PYTHONPATH with paths['/root/huanyun_daemon', '/root/huanyun_daemon']2296 INFO: checking Analysis2454 INFO: checking PYZ2542 INFO: checking PKG2556 INFO: Building because toc changed2558 INFO: Building PKG (CArchive) out00-PKG.pkgldd: can't open cache '/etc/ld.so.cache'2713 INFO: Building PKG (CArchive) out00-PKG.pkg completed successfully.2785 INFO: Bootloader /usr/lib/python2.7/site-packages/PyInstaller/bootloader/Linux-32bit/run2788 INFO: checking EXE2790 INFO: Building EXE because out00-EXE.toc is non existent2791 INFO: Building EXE from out00-EXE.toc2795 INFO: Appending archive to ELF section in EXE /root/huanyun_daemon/build/hy_daemon/hy_daemonTraceback (most recent call last): File "/usr/bin/pyinstaller", line 9, in <module> load_entry_point('PyInstaller==3.2.1', 'console_scripts', 'pyinstaller')() File "/usr/lib/python2.7/site-packages/PyInstaller/__main__.py", line 90, in run run_build(pyi_config, spec_file, **vars(args)) File "/usr/lib/python2.7/site-packages/PyInstaller/__main__.py", line 46, in run_build PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs) File "/usr/lib/python2.7/site-packages/PyInstaller/building/build_main.py", line 788, in main build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build')) File "/usr/lib/python2.7/site-packages/PyInstaller/building/build_main.py", line 734, in build exec(text, spec_namespace) File "<string>", line 26, in <module> File "/usr/lib/python2.7/site-packages/PyInstaller/building/api.py", line 411, in __init__ self.__postinit__() File "/usr/lib/python2.7/site-packages/PyInstaller/building/datastruct.py", line 161, in __postinit__ self.assemble() File "/usr/lib/python2.7/site-packages/PyInstaller/building/api.py", line 563, in assemble self.name) File "/usr/lib/python2.7/site-packages/PyInstaller/compat.py", line 486, in exec_command_all stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs) File "/usr/lib/python2.7/subprocess.py", line 710, in __init__ errread, errwrite) File "/usr/lib/python2.7/subprocess.py", line 1335, in _execute_child raise child_exceptionOSError: [Errno 2] No such file or directory
继续填坑,根据github用户提示,打包出错原因是:使用pip安装的pyinstaller,已经预编译过bootloader。需要在Openwrt平台手动重新编译,再手动安装:
1, git clone https://github.com/pyinstaller/pyinstaller.git
2, cd pyinstaller && git checkout v3.1
3, cd bootloader
4, python ./waf distclean all --no-lsb
5, python waf configure --no-lsb build install
见 https://github.com/pyinstaller/pyinstaller/issues/2050#issuecomment-248525988
0x03
以为柳暗花明,猝不及防又一坑:
重编译bootloader过程中出现:无法识别gcc -m32
在源码wscript文件找到这个-m32,看注释描述:
# This ensures proper compilation with 64bit gcc and 32bit Python # or vice versa or with manually choosen --target-arch. # Option -m32/-m64 has to be passed to cflags and linkflages. elif ctx.env.PYI_ARCH == '32bit': # It was reported that flag '-m32' does not work with gcc # on 32-bit arm Linux. So skip the -m32 flag. if not (machine() == 'arm' and is_linux): ctx.check_cc(ccflags='-m32', msg='Checking for flags -m32') ctx.env.append_value('CFLAGS', '-m32') ctx.env.append_value('LINKFLAGS', '-m32') # Set LARGE_ADDRESS_AWARE_FLAG to True. # On Windows this allows 32bit apps to use 4GB of memory and # not only 2GB. # TODO verify if this option being as default might cause any side effects. if is_win: ctx.env.append_value('LINKFLAGS', '-Wl,--large-address-aware') elif ctx.env.PYI_ARCH == '64bit': ctx.check_cc(ccflags='-m64', msg='Checking for flags -m64') ctx.env.append_value('CFLAGS', '-m64') ctx.env.append_value('LINKFLAGS', '-m64')
elif ctx.env.PYI_ARCH == '32bit':pass掉就好了:
# This ensures proper compilation with 64bit gcc and 32bit Python # or vice versa or with manually choosen --target-arch. # Option -m32/-m64 has to be passed to cflags and linkflages. elif ctx.env.PYI_ARCH == '32bit': pass # It was reported that flag '-m32' does not work with gcc # on 32-bit arm Linux. So skip the -m32 flag. # if not (machine() == None and machine() == 'arm' and is_linux): # ctx.check_cc(ccflags='-m32', msg='Checking for flags -m32') # ctx.env.append_value('CFLAGS', '-m32') # ctx.env.append_value('LINKFLAGS', '-m32') # Set LARGE_ADDRESS_AWARE_FLAG to True. # On Windows this allows 32bit apps to use 4GB of memory and # not only 2GB. # TODO verify if this option being as default might cause any side effects. # if is_win: # ctx.env.append_value('LINKFLAGS', '-Wl,--large-address-aware') elif ctx.env.PYI_ARCH == '64bit': ctx.check_cc(ccflags='-m64', msg='Checking for flags -m64') ctx.env.append_value('CFLAGS', '-m64') ctx.env.append_value('LINKFLAGS', '-m64')
修改完毕,继续编译bootloader,根据提示增加需要的头文件,即可通过编译
0x04
最后一步,回到顶层目录,手动安装pyinstaller:
python setup.py install
搞定,附上一个打包成功的截图:总结:安装gcc-->修改bootloader的wscript文件-->编译-->安装
第一次写博客,希望能帮助到有需要的人
- OpenWrt MT7621使用pyinstaller打包失败解决办法
- 使用Pyinstaller打包exe
- pyinstaller打包pyqt5常见问题解决办法
- 使用Pyinstaller打包Python脚本
- Ubuntu使用pyinstaller打包python
- 使用pyinstaller打包Python应用程序
- 使用pyInstaller打包py文件
- 使用pyinstaller对python打包
- 使用PyInstaller打包Python程序
- Python3.6用Pyinstaller打包的解决办法
- 使用pyinstaller 打包程序后,运行Failed to execute script MainPage 报错,解决办法
- pyinstaller打包
- PyInstaller打包
- Pyinstaller打包
- openwrt系统mt7621固件编译
- linux下使用pyinstaller打包python脚本
- 使用pyinstaller打包python为exe文件
- 使用pyInstaller打包的一点经验
- MFC中listctrl图片拖拽效果
- 阻塞等待和忙等待,以及超时问题
- Fragment切换 replace 和 add 的比较 以及最佳方案
- Android Studio 引入第三方库
- Android WebView页面结束后视频播放还有声音问题
- OpenWrt MT7621使用pyinstaller打包失败解决办法
- BASE64编码、解码的C语言实现
- PHP提高in_array查找元素的方法
- android: viewpager+将activity转化成view
- 设置Jmeter的maven依赖,及maven编译的设置
- 常用正则表达式
- linux获取本地时间以及转换成time_t类型
- intellij idea 项目转maven
- 22个值得收藏的Android开源代码-UI篇