P403n1x87 / austin

Python frame stack sampler for CPython
https://pypi.org/project/austin-dist/
GNU General Public License v3.0
1.89k stars 54 forks source link

Can't run script with local package import #212

Closed StefanHeng closed 8 months ago

StefanHeng commented 9 months ago

I'm able to profile from a sample script (simple for loop) to test the pipeline is working, e.g.

sudo austin -i 1ms --pipe python test-lang.py > sample_test.austin

But when I actually use this for my use case: a script that imports a local package, I got ModuleNotFoundError, see below:

➜ sudo austin -i 100 --pipe /Users/stefanhg/opt/anaconda3/envs/llm-ie-gen/bin/python "/Users/stefanhg/Documents/Georgia Tech/Research/LLM fo
r IE Data Gen/LLM-Data-Gen-IE/chore/generate.py" > generate.austin
Traceback (most recent call last):
  File "/Users/stefanhg/Documents/Georgia Tech/Research/LLM for IE Data Gen/LLM-Data-Gen-IE/chore/generate.py", line 2, in <module>
    from src.util import *
ModuleNotFoundError: No module named 'src'
P403n1x87 commented 9 months ago

@StefanHeng I suspect this is due to the fact that the src folder is not on the PYTHONPATH. Does

sudo /Users/stefanhg/opt/anaconda3/envs/llm-ie-gen/bin/python "/Users/stefanhg/Documents/Georgia Tech/Research/LLM for IE Data Gen/LLM-Data-Gen-IE/chore/generate.py"

work? My guess is that this command would fail with the same error. For this to work, I think you should set the PYTHONPATH to include the location of the src folder for the command after sudo (or allow sudo to pass the PYTHONPATH variable over to the command).