Search code examples
pythontimepython-importimporterrormicropython

ImportError: can't import name perf_counter. What may be the reason?


I`ve been working on my code for Micropython-flashed ESP8266, and well... this error occured:

from time import perf_counter

ImportError: can't import name perf_counter

I believe that the whole code itself is irrelevant, as the problem occurs during the import itself. What may be relevant though, is the list of functions imported, which looks strange to me:

>>> import time
>>> dir(time)
['__class__', '__name__', '__dict__', 'gmtime', 'localtime', 'mktime', 'sleep', 'sleep_ms', >'sleep_us', 'ticks_add', 'ticks_cpu', 'ticks_diff', 'ticks_ms', 'ticks_us', 'time', 'time_ns']

I'm currently using Python version 3.9.0

I have tried looking up the failure on google, but found only the older failures that are associated with time.clock removal and its later replacement with time.perf_counter.


Solution

  • In micropython, according to its documentation the time module doesn't have perf_counter.