Facing problem to test Energy Consumption by a factorial function with Python module "pyRAPL"

I would like to calculate energy consumption. That's why I have used the following program, unfortunately it gave errors.

MWE:

#need python3.7 to run this
from math import *
import time # time module is used to delay your program for a bit so that you can get a reading, that is not zero
        #but delay will/might give you more noise from the system
import pyRAPL
a=1

pyRAPL.setup()
measure= pyRAPL.Measurement('bar')


measure.begin()         #to begin a measurement
for i in range (100):
    a=a*(i+1)

print (a)

time.sleep(0.001)       #this time delay (in seconds) is the approximate minimum time of which it gives a reading, any duration lesser                  #than this might yield '0' energy consumption  

measure.end()           #to end the measurement

val =measure.result     #output the result by the following

print (val)     

#the above result will contain 5 values 
#access one by one with the following syntax

print ('label= ',val.label) 
print ('timestamp= ', val.timestamp)    #it gives the exact time of initialisation of measurement, (in epoch) needs to be converted to date and time format
print ('duration= ', val.duration)  #gives the duration of program running between begin() and end()


print ('energy consumed by CPU= ', val.pkg[0])  #value of energy consumption by the CPU in micro Joules  <==== We need this

print ('dram value = ',val.dram[0]) #value of RAM energy consumption (in seconds) <--- needs to be converted, not so sure how

Errors result:

enter image description here

How can I fix this problem?


Looks like one of the imported packages (probably pyRAPL) only works on Linux, there is no /sys pseudo filesystem on macOS.