'Error in time library in python and can't install time

I have this code

class Timer():
def __init__(self, synch=None):
    self.synch = synch or (lambda: None)
    self.synch()
    self.times = [time.time()]
    self.total_time = 0.0

def __call__(self, include_in_total=True):
    self.synch()
    self.times.append(time.time())
    delta_t = self.times[-1] - self.times[-2]
    if include_in_total:
        self.total_time += delta_t
    return delta_t

and I get the error

self.times = [time.time()] NameError: name 'time' is not defined

I have imported time but haven't installed it cause I was told it's built in. When I try to install it I get the error

no such option: --build-dir

when I downgrade pip to 20.2.4 it tells me that I cant install time without the newest version of pip. What should I do?



Solution 1:[1]

I would leave a comment but I don't have enough reputation. However, the time module is built in. I don't understand why you are trying to install time via pip. Try making a very simple python file that simply returns the result of time.time(). If that works, then something is wrong with your code. If that doesn't work, then the time module is likely missing from your python installation.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1