Search code examples
pythonpython-3.xlinuxmodulesudo

How to run pyRAPL on Linux


I'm working on a Linux machine. I need to use pyRAPL with python3.8. I have installed pyRAPL. The installation was successful. I went into interpreter (Python3.8) and checked. It imports.

PermissionError: [Errno 13] Permission denied: ’/sys/class/powercap/intel-ra[l/intel-rapl:0/energy_uj'

So to get around this error I run the code as sudo python3.8 foo.py, but when I do that I get the module not found error for numpy.

Now it doesn't matter which module I import. When I run the code with sudo python3.8 foo.py command, whichever module is there on the first line of my python script, it takes that, and throws a "module not found" error with that. (yes, I tested this).

So this isn't a NumPy specific question.

Now I can run the code just as python3.8 foo.py but this will give me the pyRAPL File Permission error. I need to use the pyRAPL library for my project so I can't just comment that out and go ahead.

So I'm stuck in a loop.

No sudo = pyRAPL file permission error.

Yes sudo = module not found error.

Please help me.


Solution

  • You report two problems.

    1. The Permission error can be resolved with $ sudo chmod -R a+r /sys/class/powercap/intel-rapl or with the similar command $ sudo chown -R energy /sys/class/powercap/intel-rapl.
    2. The Not Found error can be fixed by ensuring root uses same $PATH as your energy user.

    Rather than doing global installs for whole server, consider using conda. Then adjusting PATH would be a matter of $ conda activate my-rapl-env, whether you are root or an ordinary user.