0

I tries to run python -m cProfile simple_test_script.py. I'm on Windows 7, Python 2.7.10.

simple_test_script.py:

import numpy as np
from numpy.linalg import eigvals

def run_experiment(niter=100):
    K = 100
    results = []
    for _ in xrange(niter):
        mat = np.random.randn(K, K)
        max_eigenvalue = np.abs(eigvals(mat)).max()
        results.append(max_eigenvalue)
    return results
some_results = run_experiment()
print 'Largest one we saw: %s' % np.max(some_results)

I get this error:

File "<ipython-input-13-6634cb53f497>", line 1
    python -m cProfile simple_test_script.py
                     ^
SyntaxError: invalid syntax

I read this documentation: https://docs.python.org/2/library/profile.html

(Use profile instead of cProfile if the latter is not available on your system.)

I tried profile instead of cProfile but the the same error. Any clues how i can call cProfile?

Dan D.
  • 73,243
  • 15
  • 104
  • 123
Isak La Fleur
  • 4,428
  • 7
  • 34
  • 50

2 Answers2

4

It seems like you were running the following command inside IPython:

python -m cProfile simple_test_script.py

You should just run it in your shell.

satoru
  • 31,822
  • 31
  • 91
  • 141
3

As satoru suggested, you would normally run a command like this in your shell/terminal/console (for everyday usage, these basically mean the same thing). However, you can also run it from inside IPython, e.g.:

%run -m cProfile simple_test_script.py

(the % symbol is part of the command, IPython has a few special commands that start with %)

Isak La Fleur
  • 4,428
  • 7
  • 34
  • 50
Marius
  • 58,213
  • 16
  • 107
  • 105