142

This is useful for debugging (hence programming related). On linux, we can use the command

strace -feopen python myfile.py

to figure out which python modules and shared objects are loaded. Is there an equivalent one-liner on macOS X?

1 Answer 1

192

I suppose you meant strace -fetrace=open?

dtruss -f -t open python myfile.py
10
  • 1
    Hi ephemient, I just tested your version of strace (with -fetrace=open) and it gave exactly the same outuput as my example. I look forward to testing your dtruss command shortly. Thanks for the quick response!
    – Setjmp
    Dec 18, 2009 at 6:43
  • 2
    Somehow, today, sudo dtruss doesn't work for me. It's as if Python is not executed at all! Jul 18, 2013 at 14:27
  • 2
    @qarma sudo-ing back again might solve your problem: serverfault.com/questions/215510/…
    – ErikR
    Oct 26, 2013 at 2:51
  • 32
    dtruss requires root privileges, but you might not want to run the command you want traced as root. Consider sudo dtruss -f -t open sudo -u $USER python myfile.py Jul 27, 2014 at 17:48
  • 12
    Getting an error with $ sudo dtruss -f -t open sudo -u $USER python: ` dtrace: system integrity protection is on, some features will not be available` and then dtrace: failed to execute sudo: dtrace cannot control executables signed with restricted entitlements
    – blueyed
    Feb 5, 2018 at 16:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.