Python %mprun 抛出 TypeError
Python %mprun throws TypeError
我无法让 Python memory line profiler 工作。每当我从 IPython 中 运行 %mp运行 时,我都会得到错误
TypeError: unicode argument expected, got 'str'
我使用的是我能想到的最简单的例子。
In [1]: %load_ext memory_profiler
In [2]: from mpruntest import func
In [3]: A = rnd.randn(1000, 1000)
In [4]: %mprun -f func func(A)
给出:
/Users/markvdw/anaconda/lib/python2.7/site-packages/memory_profiler.pyc in show_results(prof, stream, precision)
600 'Line Contents')
601
--> 602 stream.write('Filename: ' + filename + '\n\n')
603 stream.write(header + '\n')
604 stream.write('=' * len(header) + '\n')
TypeError: unicode argument expected, got 'str'
mpruntest
包含:
import numpy as np
def func(x):
y = x**2.0
z = np.exp(y)
return z
这是一个与 Python 2 相关的错误。我刚刚发布了 memory_profiler (0.41) 的新版本,应该可以解决这个问题。现在的输出是您所期望的:
Line # Mem usage Increment Line Contents
================================================
11 42.5 MiB 0.0 MiB def func(x):
12 50.2 MiB 7.6 MiB y = x**2.0
13 57.8 MiB 7.6 MiB z = np.exp(y)
14 57.8 MiB 0.0 MiB return z
我无法让 Python memory line profiler 工作。每当我从 IPython 中 运行 %mp运行 时,我都会得到错误
TypeError: unicode argument expected, got 'str'
我使用的是我能想到的最简单的例子。
In [1]: %load_ext memory_profiler
In [2]: from mpruntest import func
In [3]: A = rnd.randn(1000, 1000)
In [4]: %mprun -f func func(A)
给出:
/Users/markvdw/anaconda/lib/python2.7/site-packages/memory_profiler.pyc in show_results(prof, stream, precision)
600 'Line Contents')
601
--> 602 stream.write('Filename: ' + filename + '\n\n')
603 stream.write(header + '\n')
604 stream.write('=' * len(header) + '\n')
TypeError: unicode argument expected, got 'str'
mpruntest
包含:
import numpy as np
def func(x):
y = x**2.0
z = np.exp(y)
return z
这是一个与 Python 2 相关的错误。我刚刚发布了 memory_profiler (0.41) 的新版本,应该可以解决这个问题。现在的输出是您所期望的:
Line # Mem usage Increment Line Contents
================================================
11 42.5 MiB 0.0 MiB def func(x):
12 50.2 MiB 7.6 MiB y = x**2.0
13 57.8 MiB 7.6 MiB z = np.exp(y)
14 57.8 MiB 0.0 MiB return z