我正在尝试 运行 一个 python 脚本,但无法识别属性,但我可以导入 psutil

I am trying to run a python script but an attribute isn't recognised but I can import psutil

当我尝试从 python3

中的 psutil 模块访问属性时出现此错误
2016-05-17 18:15:44,216 BOOT                 pyom| Logging system initialized.
2016-05-17 18:15:44,279 BOOT                 pyom| Entering Game Loop
Traceback (most recent call last):
  File "/Users/duys/pyom/Rom24/pysrc/pyom.py", line 80, in <module>
    Pyom()
  File "/Users/duys/pyom/Rom24/pysrc/pyom.py", line 76, in Pyom
    game_loop(server)
  File "/Users/duys/pyom/Rom24/pysrc/comm.py", line 265, in game_loop
    start_snapshot = sys_utils.ResourceSnapshot()
  File "/Users/duys/pyom/Rom24/pysrc/sys_utils.py", line 29, in __init__
    proc_io = proc.io_counters()
AttributeError: 'Process' object has no attribute 'io_counters'

我不明白,因为我可以成功导入模块 psutils 并浏览 psutil 我找到了方法 io_counters..

即使在我的 PyCharm 上设置项目也表明已找到 io_counters,但是当我尝试 运行 时,我得到了那个错误?

这是失败之处的代码片段:

import psutil
import logging
logger = logging.getLogger()


def sysTimeStamp(timeval):
    """
    Formats a raw time value into a formatted string in a standard format.

    :param timeval:
    :return:
    """
    return datetime.fromtimestamp(timeval).strftime("%Y-%m-%d %H:%M:%S")


class ResourceSnapshot:
    """
    Creates a snapshot of system information as an object.
    """
    def __init__(self):
        sysmem = psutil.virtual_memory()
        proc = psutil.Process()
        proc_io = proc.io_counters()

谁能给我指出正确的方向?

来自documentation of Process.io_counters()

OSX is not supported.
[...]
Availability: all platforms except OSX and Solaris

该属性不存在,因为您正在 OS X 上执行脚本。看到 source code, which only includes the method if the underlying platform-specific process class has that attribute. The OS X implementation 没有提供它,因为 OS 本身没有提供这个信息。