'ImportError: cannot import name cbook' when using PyCharm's Profiler

12,909

Solution 1

I encountered the same error today, although probably for a different reason - the packages for matplotlib and/or six appear to be broken.

Resolved it by downgrading to the previous versions:

conda install six=1.10.0
conda install matplotlib=2.0.2

Solution 2

I had the same issue. Downgrading to matplotlib 2.0.2 seems to fix it.

pip uninstall matplotlib
pip install matplotlib==2.0.2

Solution 3

I had this error in jupyter but not IPython. Fixed with $ conda install matplotlib=2.0.2 as above but six not downgraded. Don't forget (as I did) to restart the kernel.

Share:
12,909
CiaranWelsh
Author by

CiaranWelsh

Updated on June 26, 2022

Comments

  • CiaranWelsh
    CiaranWelsh almost 2 years

    I am trying to run the PyCharm profiler but I get the following error message:

    Traceback (most recent call last):
      File "/home/b3053674/ProgramFiles/pycharm-2017.1.4/helpers/profiler/run_profiler.py", line 164, in <module>
        profiler.run(file)
      File "/home/b3053674/ProgramFiles/pycharm-2017.1.4/helpers/profiler/run_profiler.py", line 89, in run
        execfile(file, globals, globals)  # execute the script
      File "/home/b3053674/Documents/pycotools/pycotools/tasks.py", line 38, in <module>
        import viz,errors, misc, _base, model
      File "/home/b3053674/Documents/pycotools/pycotools/viz.py", line 53, in <module>
        import matplotlib.pyplot as plt
      File "/home/b3053674/anaconda2/envs/pycotools/lib/python2.7/site-packages/matplotlib/__init__.py", line 124, in <module>
        from . import cbook
    ImportError: cannot import name cbook
    Snapshot saved to /home/b3053674/.PyCharm2017.1/system/snapshots/pycotools30.pstat
    
    Process finished with exit code 1
    

    I am using a conda environment which I have switched to in the terminal:

    $ source activate <env>
    

    then updated matplotlib

    $pip install matplotlib --upgrade
    

    and six just for good measure

    $pip install six --upgrade
    

    (note that I've also manually deleted these packages from site-directory of my environment and reinstalled just incase --upgrade wasn't behaving)

    I've looked here and here and neither solutions solved my problem.

    I've also switched the PyCharm Run configurations to use each of my conda environments in turn all of which produce the same error.

    Note that the profiler has worked before in the past and the code works fine when I use the normal way of executing the code. Does anybody have any idea of what is going on?

    Thanks