I have a main.py
script in my project that runs a model which is organized into a python package. The project structure looks like this:
project/
model/
data/
...
__init__.py
...
tests/
...
main.py
integrator.py
utils.py
When I run main.py directly i.e. python main.py
it works fine. However, I am trying to profile main.py using:
python -m cProfile -o main.py
and get the following error:
Traceback (most recent call last):
File "C:\Users\pbreach\Anaconda3\lib\runpy.py", line 184, in _run_module_as_main
"__main__", mod_spec)
File "C:\Users\pbreach\Anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\pbreach\Anaconda3\lib\cProfile.py", line 160, in <module>
main()
File "C:\Users\pbreach\Anaconda3\lib\cProfile.py", line 155, in main
parser.print_usage()
File "C:\Users\pbreach\Anaconda3\lib\optparse.py", line 1587, in print_usage
print(self.get_usage(), file=file)
File "C:\Users\pbreach\Anaconda3\lib\optparse.py", line 1573, in get_usage
self.expand_prog_name(self.usage))
File "C:\Users\pbreach\Anaconda3\lib\optparse.py", line 1550, in expand_prog_name
return s.replace("%prog", self.get_prog_name())
File "C:\Users\pbreach\Anaconda3\lib\optparse.py", line 1545, in get_prog_name
return os.path.basename(sys.argv[0])
IndexError: list index out of range
I am aware of the difference between python module.py
and python -m module
to the extent of this answer (not very)... But I'm not sure what I'm doing wrong here. From the traceback it seems like not enough arguments were passed to the script, but I'm not that familiar with cProfile.
Any ideas as to why this error is coming about? How can I get the code to profile?