Get CPU count from Python

Python psutil allows accessing numerous aspects of system parameters, including CPU count. We recommend using a recent version of PSutil to cover more computing platforms.

Ncpu = psutil.cpu_count(logical=False)

usually gives the physical CPU count.

PSutil uses Python script and compiled C code to determine CPU count–it’s not just a simply Python script you can copy to your project trivially. I’m not saying one couldn’t vendor PSutil cpu_count, just that it’s not completely trivial to do so.

Related: Matlab CPU count