Tags

, ,

I was experimenting with Python’s memory_profiler module and suddenly started getting following error:

$ python -m memory_profiler memProf.py
Traceback (most recent call last):
  File “/usr/lib/python2.7/runpy.py”, line 162, in _run_module_as_main
    “__main__”, fname, loader, pkg_name)
  File “/usr/lib/python2.7/runpy.py”, line 72, in _run_code
    exec code in run_globals
  File “/usr/local/lib/python2.7/dist-packages/memory_profiler.py”, line 14, in <module>
    import subprocess
  File “/usr/lib/python2.7/subprocess.py”, line 432, in <module>
    import pickle
  File “pickle.py”, line 8, in <module>
    
NameError: name ‘profile’ is not defined
Error in sys.excepthook:
Traceback (most recent call last):
  File “/usr/lib/python2.7/dist-packages/apport_python_hook.py”, line 66, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File “/usr/lib/python2.7/dist-packages/apport/__init__.py”, line 1, in <module>
    from apport.report import Report
  File “/usr/lib/python2.7/dist-packages/apport/report.py”, line 12, in <module>
    import subprocess, tempfile, os.path, urllib, re, pwd, grp, os
  File “/usr/lib/python2.7/subprocess.py”, line 432, in <module>
    import pickle
  File “pickle.py”, line 8, in <module>
    
NameError: name ‘profile’ is not defined

Original exception was:
Traceback (most recent call last):
  File “/usr/lib/python2.7/runpy.py”, line 162, in _run_module_as_main
    “__main__”, fname, loader, pkg_name)
  File “/usr/lib/python2.7/runpy.py”, line 72, in _run_code
    exec code in run_globals
  File “/usr/local/lib/python2.7/dist-packages/memory_profiler.py”, line 14, in <module>
    import subprocess
  File “/usr/lib/python2.7/subprocess.py”, line 432, in <module>
    import pickle
  File “pickle.py”, line 8, in <module>
    
NameError: name ‘profile’ is not defined

I checked the installation and validated the run-time environment, but everything looked fine. Then I took a closer look at the error traces.

  File “pickle.py”, line 8, in <module>

NameError: name ‘profile’ is not defined

There was no pickling in my code! Why is pickle module in the error log?

Then I checked the current directory and saw a file with name “pickle.py”, Bingo! I had created this file for another test and mistakenly named as “pickle.py” that coincides with standard Python pickle module.

So, fix was to rename this file to a modest name and delete its “pyc” file.

Advertisements