2

I'm using a Ubuntu 22.04 and Arduino IDE 1.8.19 for my ESP8266 Projects.

Yesterday I upgraded to 3.1.1 (using board library manager), and right after that - I got the following message (few seconds after compilation start):

Traceback (most recent call last):
  File "/home/guy/snap/arduino/85/.arduino15/packages/esp8266/hardware/esp8266/3.1.1/tools/mkbuildoptglobals.py", line 846, in <module>
    sys.exit(main())
  File "/home/guy/snap/arduino/85/.arduino15/packages/esp8266/hardware/esp8266/3.1.1/tools/mkbuildoptglobals.py", line 759, in main
    if time.time_ns() < os.stat(commonhfile_fqfn).st_mtime_ns:
AttributeError: module 'time' has no attribute 'time_ns'
exit status 1
Error compiling for board LOLIN(WEMOS) D1 R2 & mini.

Steps done to find the reason:

  1. Empty Sketch - occurs.
  2. Any other ESP8266 board - occurs.
  3. Going back to prior version, 3.1.0 - occurs.
  4. Going back to 3.0.2 - OK!
  5. Checking 3.1.1 on Mac, same IDE version - OK!

Any ideas why ? Am I the only one ?

Guy

7
  • The error tells you, that the time.time_ns() python function does not exist. This function was added to the python time lib with Python3 version 3.7. The most likely scenario I can imagin here is, that a python 3.6 or lower version is installed on your ubuntu and therefor the board software does not find the requiered function. Open a terminal and enter python --version or python3 --version, and make sure you have at least python V 3.7 installed. I would recommend to install 3.10+ to have the newest version and avoid missing other libs and language features. Commented Jan 21, 2023 at 11:42
  • @PeterPaulKiefer Typing guy@linux:~$ python3 --version returned Python 3.10.6
    – guyd
    Commented Jan 21, 2023 at 18:24
  • i have the same problem Ubuntu 22.04 IDE 1.8.19 Python 3.10.6 Error occurs after upgrading board esp8266 to 3.1.1 Commented Jan 31, 2023 at 14:08
  • 2
    Sorry for my late answer. You installed the Arduino IDE with snap?! It is possible, that Snap has its own python dependencies. I often had such problems when using snap instead of installing the software with apt or manually with a tarball. Now I always install Arduino using the tarball. There are many doc in the internet, here is one example: linuxopsys.com/topics/install-arduino-ide-on-ubuntu-20-04 Commented Feb 2, 2023 at 11:18
  • 1
    I had the same problem, although having python 3.8 installed, and I also installed Arduino through Snap. After removing the Snap installation and installing the one from arduino's website (the .AppImage file) - the issue with time_ns went away. Tnx@PeterPaulKiefer. You transform your comment into an answer and I'd gladly vote for it.
    – userfuser
    Commented Mar 5, 2023 at 9:49

2 Answers 2

2

The error tells you, that the time.time_ns() python function does not exist. This function was added to the python time lib with Python3 version 3.7.

The most likely scenario I can imagin here is, that a python 3.6 or lower version is installed on your ubuntu and therefore the board software does not find the required function.

Depending on how the ARDUINO IDE is configured, the globally installed python or a special installation of python is used. We dicussed these two possibilities in the chat and realized that in your case, snap installs its own dependency of python. I assume that the version of this python was below 3.7 and therefore the plugin was unable to find the required time function.

If the Arduino IDe would have been depent on the global python installation, it would have been enough to install a newer python (e.g. 3.10+) globally.

In you case (dependency defined by snap), the only solution I have, is to install the IDE not with snap but with the manual installation or by using apt. There are instruction in the internet like https://www.computingpost.com/how-to-install-arduino-ide-on-ubuntu-22-04-lts/.

Please check the comment of @userfuser (about usíng an .AppImage file) in the dicussion below the question also.

2

My symptoms are exactly the same.

Following uses of snap for installation or Arduino 1.8.19, I have found snap core recently updated core-18 from Ubuntu 22.04. The consequence since are drastic, starting with only Python 3.10, everything was almost working but I found the error inside mkbuildoptglobals.py inside the Arduino IDE output:

-----------------------
*** Traceback (most recent call last):
  File "/home/maxiste/snap/arduino/71/.arduino15/packages/esp8266/hardware/esp8266/3.1.2/tools/mkbuildoptglobals.py", line 831, in <module>
    rc = main()
  File "/home/maxiste/snap/arduino/71/.arduino15/packages/esp8266/hardware/esp8266/3.1.2/tools/mkbuildoptglobals.py", line 744, in main
    from time import time_ns
ImportError: cannot import name 'time_ns'
-----------------------

Adding a few lines inside the Python code to allow having an output to see. The surprise tell Python 3.6 and not 3.10, so mkbuildoptglobals.py stops.

Here is the sample starting line 200:

if PYTHON_REQUIRES[0] < int(sys.version_info[0]) :
    raise SystemExit(f"{__file__}\nMinimal supported version of Python is {PYTHON_REQUIRES[0]}")
elif PYTHON_REQUIRES[1] > int(sys.version_info[1]) :
    raise SystemExit(f"{__file__}\nMajor version of Python required is {PYTHON_REQUIRES[0]}.{PYTHON_REQUIRES[1]}, your version {sys.version_info[0]}.{sys.version_info[1]}.\n")
else:
    from sys import stdout 
    sys.stdout.write(f"\nArduino Board project use Python version {sys.version_info[0]}.{sys.version_info[1]}\n\n") 
    pass

And it shows me also a Python 3.6 and searching inside snap path of your home you should find:

/snap/gnome-3-28-1804/199/usr/bin/python3.6
/snap/gnome-3-28-1804/199/usr/share/binfmts/python3.6
/snap/gnome-3-28-1804/199/usr/share/lintian/overrides/python3.6
/snap/core18/2810/usr/bin/python3.6
/snap/core18/2810/usr/share/binfmts/python3.6
/snap/core18/2810/usr/share/lintian/overrides/python3.6

In my case it's update of gnome-3-28 and updating core18 from snap that push and under version of Python for Arduino.

And what is worse, for all those are trying Ubuntu 22.04, it automatically updates components in snap without touching it. I have even Chromium updating to a version automatically and left the compatibility with TASMOTA and package for esp-s2/s3, rsp-c3 and esp32 also.

The rest to help to pass the pill I do have to change platform.txt with following hack:

  • As one line of recipe tell information about uses of Python here what change back to point on your Python3.10 .
recipe.hooks.sketch.prebuild.pattern="{runtime.tools.python3.path}/python3" -I "{runtime.tools.signing}" --mode header --publickey "{build.source.path}/public.key" --out "{build.path}/core/Updater_Signing.h" 

and where you found

{runtime.tools.python3.path}/python3

you change it for

{runtime.tools.python3.path}/../../../../../usr/bin/python3.10

Where my snap root is: /snap/gnome-3-28-1804/199/usr/bin and all runtime application from Arduino had moved here.

So it's matter of recipe and wrong draw back from Ubuntu.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.