rkern / line_profiler

(OLD REPO) Line-by-line profiling for Python - Current repo ->
https://github.com/pyutils/line_profiler
Other
3.6k stars 254 forks source link

UnpicklingError in both py2 and py3 #123

Open remdragon opened 6 years ago

remdragon commented 6 years ago

I just downloaded line_profiler but my first attempt to use it generated a traceback:

Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) [MSC v.1500 32 bit (Intel)] on win32

D:\censored>kernprof test7.py
test 0: 0.011
test 1: 0.34
test 2: 0.45
Wrote profile results to test7.py.prof

D:\censored>python -m line_profiler test7.py.prof
Traceback (most recent call last):
  File "c:\Python27\lib\runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "c:\Python27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "c:\Python27\lib\site-packages\line_profiler.py", line 422, in <module>
    main()
  File "c:\Python27\lib\site-packages\line_profiler.py", line 418, in main
    lstats = load_stats(args[0])
  File "c:\Python27\lib\site-packages\line_profiler.py", line 408, in load_stats
    return pickle.load(f)
cPickle.UnpicklingError: invalid load key, '{'.

Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32

D:\censored>kernprof test7.py
test 0: 0.013
test 1: 0.31
test 2: 0.41
Wrote profile results to test7.py.prof

D:\censored>python -m line_profiler test7.py.prof
Traceback (most recent call last):
  File "D:\Python36-32\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "D:\Python36-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\Python36-32\lib\site-packages\line_profiler.py", line 422, in <module>
    main()
  File "D:\Python36-32\lib\site-packages\line_profiler.py", line 418, in main
    lstats = load_stats(args[0])
  File "D:\Python36-32\lib\site-packages\line_profiler.py", line 408, in load_stats
    return pickle.load(f)
_pickle.UnpicklingError: invalid load key, '\xfb'.
mlpacheco commented 5 years ago

I am having the same issue.

abhisheksgumadi commented 5 years ago

Anyone managed to solve this?

jpreiss commented 5 years ago

I am also seeing this problem with Python 3.7 on mac OS.

yurymann commented 5 years ago

Same issue with python 2.7.13. I wonder if anyone is still supporting this project.

UPDATE: It turned out I was dumping from cProfile rather than line_profiler. So in my case it's explained.

jspam commented 5 years ago

To elaborate on yurymann's comment, it seems that kernprof does not use line_profiler by default, but cProfile. One needs to specify -l to use line_profiler. So one should either do:

$ kernprof -l test.py
Wrote profile results to test.py.lprof
$ python -m line_profiler test.py.lprof

or

$ kernprof test.py
Wrote profile results to test.py.prof
$ python -m pstats test.py.prof