3

I'm trying to read Mac OS ASL log file with Python by using this asl package. I think the package is successfully installed but I can't import it. Below are the error messages:

Traceback (most recent call last):
  File "", line 1, in 
  File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 20, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/Users/serenasmac1/PycharmProjects/Test2/venv/lib/python3.5/site-packages/asl/__init__.py", line 8, in 
    from ._asl import *
  File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 20, in do_import
    module = self._system_import(name, *args, **kwargs)
ImportError: No module named 'asl._asl'

As far as I understood, init.py is calling a ._asl module but it doesn't exist. Is my understanding correct? How can I fix it?

Also, I've found this script which seems can read asl file. I'm trying it in parallel. I've searched a lot but only found this script and the ASL package. I'd really appreciate if anybody can share the knowledge of how to read asl file with Python. Thanks a lot!

Here is the how the package was installed: enter image description here

Serena
  • 67
  • 8
  • If you can't import the module, it is not successfully installed. How did you install it? – Daniel Pryden Apr 04 '18 at 21:59
  • @Daniel: I used pip install. When I do pip search asl, I can see the package and it says INSTALLED: 1.0.1 (latest). However, when I run python3 -m asl, it returns "/Users/serenasmac1/PycharmProjects/Test2/venv/bin/python3: Error while finding spec for 'asl.__main__' (: No module named 'asl._asl'); 'asl' is a package and cannot be directly executed ". I'm not sure what the problem is. – Serena Apr 04 '18 at 22:15
  • 1
    did you install it with pip3 (it might be installed in 2.7)? – manandearth Apr 04 '18 at 22:19
  • @manandearth. No I did with pip (usually it is installed in 3.5 by default) but I just did pip3, it returned "Requirement already satisfied: asl in ./venv/lib/python3.5/site-packages" – Serena Apr 04 '18 at 22:25
  • 1
    [This issue was already reported and fixed](https://bitbucket.org/ronaldoussoren/asl/pull-requests/1/adding-ext_modules-to-metadata-this-is-not/diff), however, because the author of `asl` didn't bother, the fix is still unmerged. You can clone the repo, apply the fix (it's just one line with `ext_modules` to add to `setup.py`) and install from the fixed repo: `pip install path/to/ast/repo`. – hoefling Apr 04 '18 at 22:37
  • @hoefling this doesn't appear to actually add `._asl` to the `asl` module namespace. Can you confirm your suggestion worked on your machine? – duhaime Apr 04 '18 at 23:03
  • @RonaldOussoren - any thoughts on this thread? – duhaime Apr 04 '18 at 23:09
  • @hoefling Thanks a lot for the info and detailed instructions! I couldn't have found this myself. – Serena Apr 05 '18 at 20:58
  • @duhaime I just tried it and it worked on my machine, although I'm not sure why. – Serena Apr 05 '18 at 20:58
  • 1
    @Serena glad to help a fellow berliner! :-) – hoefling Apr 05 '18 at 21:22

1 Answers1

4

It looks like the asl package is actually broken. I'd use the syslog executable that ships with OSX:

from subprocess import check_output

cmd = 'syslog -f /private/var/log/asl/2018.04.03.U501.asl'
log = check_output(cmd.split())
print(log)
duhaime
  • 25,611
  • 17
  • 169
  • 224
  • @Serena excellent--I love a simple solution. I didn't know about these files, so I'm glad you asked the question. Feel free to click the green checkbox to let others know this solution worked for you! – duhaime Apr 05 '18 at 19:43