Python line_profiler 安装

dav*_*o36 5 python installation enthought canopy

嗨,我是 Python 新手程序员。我想要逐行分析,因此尝试安装 line_profiler 包。但它不起作用。这是我所做的:

顺便说一下,我使用的是 64 位 Windows 8.1,并且正在使用 Enthought Canopy。

我从这里得到了 Windows 安装包:https : //pypi.python.org/pypi/line_profiler并安装了它。

它在 line_profiler 站点上说 a) 我不需要构建它或需要 Cython,b) 我应该这样做:

对于 IPython 0.11+,您可以通过编辑 IPython 配置文件 ~/.ipython/profile_default/ipython_config.py 将“line_profiler”项添加到扩展列表中来安装它:

c.TerminalIPythonApp.extensions = ['line_profiler', ]

我重新启动了 Canopy,没有运气。应该有一个魔法命令 %lprun。它不在那里。

我尝试了 %load_ext line_profiler 但收到了这条消息:

C:\Users\OEM\AppData\Local\Enthought\Canopy\User\lib\site-packages\line_profiler.py in () 10 import sys 11 ---> 12 from _line_profiler import LineProfiler as CLineProfiler 13 14

导入错误:DLL 加载失败:%1 不是有效的 Win32 应用程序。

其他事情:我为此寻找了 setup.py,但找不到似乎安装在 C:\Users\OEM\AppData\Local\Enthought\Canopy\User\Lib\site-packages 中的 line_profiler文件夹。

因此,请感谢任何帮助。

小智 13

我使用的是 Windows 10,64 位

  1. 你需要去非官方的 python 二进制文件https://www.lfd.uci.edu/~gohlke/pythonlibs/
  2. 然后按“Control+F”并输入“line_profiler”,然后选择它 Searching package
  3. 我使用 Python 3.7,Windows 10 64 位。然后选择最后下载您的车轮文件
  4. 打开命令提示符(Windows+R 并输入 cmd)
  5. 将方向更改为我的下载,我在其中下载我的文件“cd 下载”
  6. 比输入此命令 C:/Users/YOUR_USER_NAME/AppData/Local/Programs/Python/Python37/Scripts/pip install "line_profiler-2.1.2-cp37-cp37m-win_amd64.whl"

在 cmd 中输出

(原始来源)


Mar*_*aff 1

尽管这个问题很老了:

如今,使用miniconda/ Anaconda,在 Win 10 64 位下安装就像一个魅力;只需conda install line_profiler在您要使用的环境中进行即可。这还会将kernprof命令/脚本添加到该环境中的路径中。

用法:

[add @profile decorators to the functions you want to profile]
kernprof -l ./your_script.py
python -m line_profiler ./your_script.py.lprof
Run Code Online (Sandbox Code Playgroud)