Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python line_profiler installation

Hi I'm a newbie Python programmer. I want line by line profiling and so have tried to install the line_profiler package. But it's not working. Here is what I have done:

By the way I'm on Windows 8.1, 64 bit and I'm using Enthought Canopy.

I got the Windows install package from here: https://pypi.python.org/pypi/line_profiler and installed it.

It says on the line_profiler site that a) I don't need to build it or need Cython, b) that I should do this:

For IPython 0.11+, you can install it by editing the IPython configuration file ~/.ipython/profile_default/ipython_config.py to add the 'line_profiler' item to the extensions list:

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

I restarted Canopy, no luck. There should be a magic command %lprun. It's not there.

I tried %load_ext line_profiler but got this message:

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

ImportError: DLL load failed: %1 is not a valid Win32 application.

Other things: I looked for a setup.py for this but couldn't find one for the line_profiler which seems to be installed in the C:\Users\OEM\AppData\Local\Enthought\Canopy\User\Lib\site-packages folder.

So any help appreciated please.

like image 350
davo36 Avatar asked Jan 16 '14 06:01

davo36


2 Answers

Im using Windows 10, 64 bit

  1. You need go to unofficial binaries for python https://www.lfd.uci.edu/~gohlke/pythonlibs/
  2. Then press "Control+F" and type 'line_profiler',then choose it Searching package
  3. Im use Python 3.7 , Windows 10 64 bit. Then choose the last Download your wheel file
  4. Open Command Prompt (Windows+R and type cmd)
  5. Change direction to my downloads, where im download my file 'cd Downloads'
  6. Than type this command C:/Users/YOUR_USER_NAME/AppData/Local/Programs/Python/Python37/Scripts/pip install "line_profiler-2.1.2-cp37-cp37m-win_amd64.whl"

Output in cmd

(Original source)

like image 54
Омар Меджидов Avatar answered Sep 22 '22 11:09

Омар Меджидов


Even though this question is quite old:

Nowadays, using miniconda/Anaconda, installation under Win 10 64-bit works like a charm; just do conda install line_profiler in the environment you are going to use. This will also add the kernprof command/script to your path in that environment.

Usage:

[add @profile decorators to the functions you want to profile]
kernprof -l ./your_script.py
python -m line_profiler ./your_script.py.lprof
like image 39
Marius Wallraff Avatar answered Sep 20 '22 11:09

Marius Wallraff