python psutil 在 linux 4 下无法安装的问题

python 2.7

psutil 0.61

linux 版本为:

Linux netweb1 2.4.21-20.ELsmp #1 SMP Wed Aug 18 20:46:40 EDT 2004 i686 i686 i386 GNU/Linux


running install
running build
running build_py
running build_ext
building '_psutil_linux' extension
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -I/opt/bmc/python273/include/python2.7 -c psutil/_psutil_linux.c -o build/temp.linux-i686-2.7/psutil/_psutil_linux.o
psutil/_psutil_linux.c: In function `set_process_cpu_affinity':
psutil/_psutil_linux.c:200: warning: passing arg 2 of `sched_setaffinity' makes pointer from integer without a cast
psutil/_psutil_linux.c:200: too many arguments to function `sched_setaffinity'
psutil/_psutil_linux.c: At top level:
psutil/_psutil_linux.h:13: warning: `linux_ioprio_get' declared `static' but never defined
psutil/_psutil_linux.h:14: warning: `linux_ioprio_set' declared `static' but never defined
error: command 'gcc' failed with exit status 1

内核 2.4 估计太老了,sched_setaffinity 只支持 三个参数,修改 psutil/_psutil_linux.c

    if (sched_setaffinity(pid, /*len,*/ (cpu_set_t *)&mask)) {

把 len 注释掉,再编译,ok通过

python 导入也正常.


linux 4 32 位,内存查询的时候,会报错



里面是没有 Inactive 的 这里就报错了:

    cached = active = inactive = None
    f = open('/proc/meminfo', 'r')
        for line in f:
            if line.startswith('Cached:'):
                cached = int(line.split()![pic](1)) * 1024
            elif line.startswith('Active:'):
                active = int(line.split()![pic](1)) * 1024
            elif line.startswith('Inactive:'):
                inactive = int(line.split()![pic](1)) * 1024
            if cached is not None \
            and active is not None \
            and inactive is not None:
            raise RuntimeError("line(s) not found")

初始 inactive = 0 即可

    cached = active = inactive = None
    inactive = 0

注意删除 _pslinux.pyc