Python 运行cProfile时语法无效
我尝试运行python-mcprofile simple_test_script.py。我使用的是Windows7,Python 2.7.10 简单测试脚本.py:Python 运行cProfile时语法无效,python,ipython,profile,cprofile,Python,Ipython,Profile,Cprofile,我尝试运行python-mcprofile simple_test_script.py。我使用的是Windows7,Python 2.7.10 简单测试脚本.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.ra
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)
我得到这个错误:
File "<ipython-input-13-6634cb53f497>", line 1
python -m cProfile simple_test_script.py
^
SyntaxError: invalid syntax
我阅读了以下文档:
如果cProfile在上不可用,请使用profile而不是cProfile
你的系统
我试着用profile代替cProfile,但同样的错误。有任何关于如何调用cProfile的线索吗?似乎您在IPython中运行以下命令:
python -m cProfile simple_test_script.py
您应该在shell中运行它。正如satoru所建议的,您通常会在日常使用的shell/terminal/console中运行这样的命令,这些基本上都是相同的意思。但是,您也可以从IPython内部运行它,例如:
%run -m cProfile simple_test_script.py
%符号是命令的一部分,IPython有一些以%开头的特殊命令,谢谢!效果非常好运行-m cProfile simple\u test\u script.pyThank you@satoru!我想在IPython内部运行它。但是谢谢你对为什么会出现错误的解释。