This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrfutil ModuleNotFoundError: No module named 'constants'

Hi,

I have installed nrfutil on my Windows 10 computer and get the following error when running it:

C:\Users\00315055>nrfutil --help
Traceback (most recent call last):
File "c:\python37\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\python37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Python37\Scripts\nrfutil.exe\__main__.py", line 5, in <module>
File "c:\python37\lib\site-packages\nordicsemi\__main__.py", line 53, in <module>
from nordicsemi.dfu.dfu_transport_serial import DfuTransportSerial
File "c:\python37\lib\site-packages\nordicsemi\dfu\dfu_transport_serial.py", line 52, in <module>
from nordicsemi.lister.device_lister import DeviceLister
File "c:\python37\lib\site-packages\nordicsemi\lister\device_lister.py", line 39, in <module>
from nordicsemi.lister.windows.lister_win32 import Win32Lister
File "c:\python37\lib\site-packages\nordicsemi\lister\windows\lister_win32.py", line 43, in <module>
from constants import DIGCF_PRESENT, DEVPKEY, DIGCF_DEVICEINTERFACE
ModuleNotFoundError: No module named 'constants'

I have the following Python version:

C:\Users\00315055>python --version
Python 3.7.4

BR / Björn

  • Hi,

    Yes, it is unfortunate. The current nrfutil release was made before Python 3.9, hence not included in our release tests. I have already reported this to the team, so it should get fixed in the next version.

    Best regards,

    Vidar

  • Thanks Vidar, great that you have a fix in your plans :-)

    Merry XMAS!

    BR / Björn

  • Hmm, I have a fresh install with 3.8.7 and I see the same error:

    ImportError: cannot import name 'DIGCF_PRESENT' from 'constants' (c:\users\someone\appdata\local\programs\python\python38\lib\site-packages\constants.py)

    This is a bummer since I need to test secure DFU for a client.

  • I am not sure if v3.8.7 has been tested. Is it an option to use the pre-buildt executables here: https://github.com/NordicSemiconductor/pc-nrfutil/releases ?

  • As of Python 3.9.6 on Win 10 and nrfutil 5.2.0 this still seems to be an issue

    C:\Users\CAD>nrfutil
    Traceback (most recent call last):
      File "C:\Users\CAD\AppData\Local\Programs\Python\Python39\Scripts\nrfutil-script.py", line 33, in <module>
        sys.exit(load_entry_point('nrfutil==5.2.0', 'console_scripts', 'nrfutil')())
      File "C:\Users\CAD\AppData\Local\Programs\Python\Python39\Scripts\nrfutil-script.py", line 25, in importlib_load_entry_point
        return next(matches).load()
      File "c:\users\cad\appdata\local\programs\python\python39\lib\importlib\metadata.py", line 77, in load
        module = import_module(match.group('module'))
      File "c:\users\cad\appdata\local\programs\python\python39\lib\importlib\__init__.py", line 127, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
      File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
      File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 850, in exec_module
      File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
      File "c:\users\cad\appdata\local\programs\python\python39\lib\site-packages\nordicsemi\__main__.py", line 53, in <module>
        from nordicsemi.dfu.dfu_transport_serial import DfuTransportSerial
      File "c:\users\cad\appdata\local\programs\python\python39\lib\site-packages\nordicsemi\dfu\dfu_transport_serial.py", line 52, in <module>
        from nordicsemi.lister.device_lister import DeviceLister
      File "c:\users\cad\appdata\local\programs\python\python39\lib\site-packages\nordicsemi\lister\device_lister.py", line 39, in <module>
        from nordicsemi.lister.windows.lister_win32 import Win32Lister
      File "c:\users\cad\appdata\local\programs\python\python39\lib\site-packages\nordicsemi\lister\windows\lister_win32.py", line 43, in <module>
        from constants import DIGCF_PRESENT, DEVPKEY, DIGCF_DEVICEINTERFACE
    ModuleNotFoundError: No module named 'constants'
    
    C:\Users\CAD>pip install constants
    Collecting constants
      Downloading constants-0.6.0.tar.gz (5.1 kB)
    Using legacy 'setup.py install' for constants, since package 'wheel' is not installed.
    Installing collected packages: constants
        Running setup.py install for constants ... done
    Successfully installed constants-0.6.0
    
    C:\Users\CAD>nrfutil
    Traceback (most recent call last):
      File "C:\Users\CAD\AppData\Local\Programs\Python\Python39\Scripts\nrfutil-script.py", line 33, in <module>
        sys.exit(load_entry_point('nrfutil==5.2.0', 'console_scripts', 'nrfutil')())
      File "C:\Users\CAD\AppData\Local\Programs\Python\Python39\Scripts\nrfutil-script.py", line 25, in importlib_load_entry_point
        return next(matches).load()
      File "c:\users\cad\appdata\local\programs\python\python39\lib\importlib\metadata.py", line 77, in load
        module = import_module(match.group('module'))
      File "c:\users\cad\appdata\local\programs\python\python39\lib\importlib\__init__.py", line 127, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
      File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
      File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 850, in exec_module
      File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
      File "c:\users\cad\appdata\local\programs\python\python39\lib\site-packages\nordicsemi\__main__.py", line 53, in <module>
        from nordicsemi.dfu.dfu_transport_serial import DfuTransportSerial
      File "c:\users\cad\appdata\local\programs\python\python39\lib\site-packages\nordicsemi\dfu\dfu_transport_serial.py", line 52, in <module>
        from nordicsemi.lister.device_lister import DeviceLister
      File "c:\users\cad\appdata\local\programs\python\python39\lib\site-packages\nordicsemi\lister\device_lister.py", line 39, in <module>
        from nordicsemi.lister.windows.lister_win32 import Win32Lister
      File "c:\users\cad\appdata\local\programs\python\python39\lib\site-packages\nordicsemi\lister\windows\lister_win32.py", line 43, in <module>
        from constants import DIGCF_PRESENT, DEVPKEY, DIGCF_DEVICEINTERFACE
    ImportError: cannot import name 'DIGCF_PRESENT' from 'constants' (c:\users\cad\appdata\local\programs\python\python39\lib\site-packages\constants.py)

Related