I am trying to compile nrfutil into a standalone executable, following the instructions at: https://github.com/NordicSemiconductor/pc-nrfutil
This works on Linux, and for Windows there are standalone executable attached to the nrfutil releases, but for mac I get the following error when attempting to use pyinstaller to generate a self-contained executable:
$ pyinstaller ./nrfutil.spec 29 INFO: PyInstaller: 3.4 30 INFO: Python: 2.7.15 35 INFO: Platform: Darwin-17.5.0-x86_64-i386-64bit 41 INFO: UPX is not available. 42 INFO: Extending PYTHONPATH with paths ['/Users/api_team/pc-nrfutil'] 42 INFO: checking Analysis 48 INFO: Building because inputs changed 48 INFO: Initializing module dependency graph... 50 INFO: Initializing module graph hooks... 109 INFO: running Analysis Analysis-00.toc 115 INFO: Caching module hooks... 118 INFO: Analyzing nordicsemi/__main__.py 2615 INFO: Processing pre-find module path hook distutils 3528 INFO: Processing pre-safe import module hook _xmlplus 7153 INFO: Loading module hooks... 7153 INFO: Loading module hook "hook-distutils.py"... 7154 INFO: Loading module hook "hook-sysconfig.py"... 7155 INFO: Loading module hook "hook-xml.py"... 7229 INFO: Loading module hook "hook-httplib.py"... 7230 INFO: Loading module hook "hook-encodings.py"... 7771 INFO: Loading module hook "hook-pkg_resources.py"... 8041 INFO: Processing pre-safe import module hook win32com 8332 INFO: checking Tree 8333 INFO: Building Tree because Tree-00.toc is non existent 8333 INFO: Building Tree Tree-00.toc 8334 INFO: Looking for ctypes DLLs 8436 INFO: Analyzing run-time hooks ... 8441 INFO: Including run-time hook 'pyi_rth_pkgres.py' 8443 INFO: Including run-time hook 'pyi_rth_multiprocessing.py' 8459 INFO: Looking for dynamic libraries 8559 INFO: Looking for eggs 8559 INFO: Using Python library /Users/api_team/miniconda3/envs/nrfutil/lib/libpython2.7.dylib 8565 INFO: Warnings written to /Users/api_team/pc-nrfutil/build/nrfutil/warn-nrfutil.txt 8607 INFO: Graph cross-reference written to /Users/api_team/pc-nrfutil/build/nrfutil/xref-nrfutil.html 8780 INFO: Appending 'binaries' from .spec 8784 INFO: checking PYZ 8788 INFO: Building because toc changed 8788 INFO: Building PYZ (ZlibArchive) /Users/api_team/pc-nrfutil/build/nrfutil/PYZ-00.pyz 9360 INFO: Building PYZ (ZlibArchive) /Users/api_team/pc-nrfutil/build/nrfutil/PYZ-00.pyz completed successfully. 9516 INFO: checking PKG 9516 INFO: Building PKG because PKG-00.toc is non existent 9516 INFO: Building PKG (CArchive) PKG-00.pkg Traceback (most recent call last): File "/Users/api_team/miniconda3/envs/nrfutil/bin/pyinstaller", line 11, in <module> sys.exit(run()) File "/Users/api_team/miniconda3/envs/nrfutil/lib/python2.7/site-packages/PyInstaller/__main__.py", line 111, in run run_build(pyi_config, spec_file, **vars(args)) File "/Users/api_team/miniconda3/envs/nrfutil/lib/python2.7/site-packages/PyInstaller/__main__.py", line 63, in run_build PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs) File "/Users/api_team/miniconda3/envs/nrfutil/lib/python2.7/site-packages/PyInstaller/building/build_main.py", line 838, in main build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build')) File "/Users/api_team/miniconda3/envs/nrfutil/lib/python2.7/site-packages/PyInstaller/building/build_main.py", line 784, in build exec(text, spec_namespace) File "<string>", line 37, in <module> File "/Users/api_team/miniconda3/envs/nrfutil/lib/python2.7/site-packages/PyInstaller/building/api.py", line 424, in __init__ strip_binaries=self.strip, upx_binaries=self.upx, File "/Users/api_team/miniconda3/envs/nrfutil/lib/python2.7/site-packages/PyInstaller/building/api.py", line 196, in __init__ self.__postinit__() File "/Users/api_team/miniconda3/envs/nrfutil/lib/python2.7/site-packages/PyInstaller/building/datastruct.py", line 158, in __postinit__ self.assemble() File "/Users/api_team/miniconda3/envs/nrfutil/lib/python2.7/site-packages/PyInstaller/building/api.py", line 259, in assemble dist_nm=inm) File "/Users/api_team/miniconda3/envs/nrfutil/lib/python2.7/site-packages/PyInstaller/building/utils.py", line 228, in checkCache dylib.mac_set_relative_dylib_deps(cachedfile, dist_nm) File "/Users/api_team/miniconda3/envs/nrfutil/lib/python2.7/site-packages/PyInstaller/depend/dylib.py", line 308, in mac_set_relative_dylib_deps dll = MachO(libname) File "/Users/api_team/miniconda3/envs/nrfutil/lib/python2.7/site-packages/macholib/MachO.py", line 95, in __init__ self.load(fp) File "/Users/api_team/miniconda3/envs/nrfutil/lib/python2.7/site-packages/macholib/MachO.py", line 110, in load self.load_header(fh, 0, size) File "/Users/api_team/miniconda3/envs/nrfutil/lib/python2.7/site-packages/macholib/MachO.py", line 147, in load_header header, fh)) ValueError: Unknown Mach-O header: 0x230d0a23 in <open file '/Users/api_team/Library/Application Support/pyinstaller/bincache00_py27_64bit/lib/linux/__init__.py', mode 'rb' at 0x10e642150>
Is there a specific version of pyinstaller that must be used? I have tried the instructions for nrfutil v3.5.1 and v4.0.0 with the same results.
There is an old github issue here that has not be addressed: https://github.com/NordicSemiconductor/pc-nrfutil/issues/118
It seems from the comments on the pc-nrfutil github issues that the maintainers would prefer issues like this to be posted here on DevZone, but I will make a Github issue as well.
As a workaround I've also attempted to use pip to install nrfutil, but that fails at runtime with the following error (again with both v3.5.1 and v4.0.0):
Starting DFU update over dfu_usb... [------------------------------------] 0% Traceback (most recent call last): File "/Users/api_team/miniconda3/envs/dfu/bin/nrfutil", line 11, in <module> sys.exit(cli()) File "/Users/api_team/miniconda3/envs/dfu/lib/python3.7/site-packages/click/core.py", line 722, in __call__ return self.main(*args, **kwargs) File "/Users/api_team/miniconda3/envs/dfu/lib/python3.7/site-packages/click/core.py", line 697, in main rv = self.invoke(ctx) File "/Users/api_team/miniconda3/envs/dfu/lib/python3.7/site-packages/click/core.py", line 1066, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/Users/api_team/miniconda3/envs/dfu/lib/python3.7/site-packages/click/core.py", line 1066, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/Users/api_team/miniconda3/envs/dfu/lib/python3.7/site-packages/click/core.py", line 895, in invoke return ctx.invoke(self.callback, **ctx.params) File "/Users/api_team/miniconda3/envs/dfu/lib/python3.7/site-packages/click/core.py", line 535, in invoke return callback(*args, **kwargs) File "/Users/api_team/miniconda3/envs/dfu/lib/python3.7/site-packages/nordicsemi/__main__.py", line 827, in usb_serial do_serial(package, port, connect_delay, flow_control, packet_receipt_notification, baud_rate, False) File "/Users/api_team/miniconda3/envs/dfu/lib/python3.7/site-packages/nordicsemi/__main__.py", line 793, in do_serial dfu.dfu_send_images() File "/Users/api_team/miniconda3/envs/dfu/lib/python3.7/site-packages/nordicsemi/dfu/dfu.py", line 129, in dfu_send_images self._dfu_send_image(self.manifest.application) File "/Users/api_team/miniconda3/envs/dfu/lib/python3.7/site-packages/nordicsemi/dfu/dfu.py", line 90, in _dfu_send_image self.dfu_transport.open() File "/Users/api_team/miniconda3/envs/dfu/lib/python3.7/site-packages/nordicsemi/dfu/dfu_transport_serial.py", line 213, in open self.__set_prn() File "/Users/api_team/miniconda3/envs/dfu/lib/python3.7/site-packages/nordicsemi/dfu/dfu_transport_serial.py", line 308, in __set_prn + map(ord, struct.pack('<H', self.prn))) TypeError: can only concatenate list (not "map") to list DFU update over USB failed
All of the above was executed in a Python 2 virtual environment.