【问题标题】:Reading ASL log file - Python读取 ASL 日志文件 - Python
【发布时间】:2018-04-04 21:57:23
【问题描述】:

我正在尝试使用this asl package 使用 Python 读取 Mac OS ASL 日志文件。我认为该软件包已成功安装,但我无法导入它。以下是错误消息:

Traceback(最近一次调用最后一次):
  文件“”,第 1 行,在
  文件“/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py”,第 20 行,在 do_import
    模块 = self._system_import(名称,*args,**kwargs)
  文件“/Users/serenasmac1/PycharmProjects/Test2/venv/lib/python3.5/site-packages/asl/__init__.py”,第 8 行,在
    从 ._asl 导入 *
  文件“/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py”,第 20 行,在 do_import
    模块 = self._system_import(名称,*args,**kwargs)
ImportError:没有名为“asl._asl”的模块

据我了解,init.py 正在调用 ._asl 模块,但它不存在。我的理解正确吗?我该如何解决?

另外,我发现this script 似乎可以读取 asl 文件。我正在并行尝试。我搜索了很多,但只找到了这个脚本和 ASL 包。如果有人可以分享如何使用 Python 读取 asl 文件的知识,我将不胜感激。非常感谢!

这是安装包的方式:

【问题讨论】:

  • 如果无法导入模块,说明没有安装成功。你是怎么安装的?
  • @Daniel:我使用了 pip install。当我执行 pip search asl 时,我可以看到包,上面写着 INSTALLED: 1.0.1 (latest)。但是,当我运行 python3 -m asl 时,它返回“/Users/serenasmac1/PycharmProjects/Test2/venv/bin/python3: Error while find spec for 'asl.__main__' (: No module named ' asl._asl');'asl'是一个包,不能直接执行".我不确定是什么问题。
  • 你是用pip3安装的吗(2.7可能会安装)?
  • This issue was already reported and fixed,然而,因为asl的作者没有打扰,修复仍然没有合并。您可以克隆存储库,应用修复(只需将 ext_modules 添加到 setup.py 的一行)并从固定存储库安装:pip install path/to/ast/repo
  • @Serena 很高兴能帮助柏林同胞! :-)

标签: python macos logfile


【解决方案1】:

看起来 asl 包实际上已损坏。我会使用 OSX 附带的 syslog 可执行文件:

from subprocess import check_output

cmd = 'syslog -f /private/var/log/asl/2018.04.03.U501.asl'
log = check_output(cmd.split())
print(log)

【讨论】:

  • @Serena 非常好——我喜欢一个简单的解决方案。我不知道这些文件,所以很高兴你问了这个问题。随意单击绿色复选框,让其他人知道此解决方案对您有用!
猜你喜欢
  • 2021-06-22
  • 1970-01-01
  • 2018-11-09
  • 1970-01-01
  • 1970-01-01
  • 2019-05-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多