I am trying to run the code below at Python 2.7 GUI:
python -m cProfile -s time abc.py
However here is the error I have:
>>> python -m cProfile -s time abc.py
>>> ^
>>> SyntaxError: invalid syntax
Any idea how can I solve it?
You need to run this from the command line, not a GUI or the interactive Python prompt. Seeing the
>>>
means you are on the interactive Python prompt.On the command line a.k.a terminal window, change to the directory in which
abc.py
is located and enter:I get this:
The option
-m
does this:The Python version is 2.7.12.
EDIT
If you want to do it from the interactive prompt, probably the easiest way is to use IPython or Jupyter Notebook. Then you can do this: