0

When executing the below


    profile = ProfileReport(df,title="Data Profile Report")
    profile.to_file("data_profile_report.html")

Here is the exception thrown


    ---------------------------------------------------------------------------
    AttributeError                            Traceback (most recent call last)
    c:\Projections 2022-08-16\Projections.py in <cell line: 4>()
          102 # %%
          103 #Creating EDA of data
          104 profile = ProfileReport(df_cdap,title="CDAP Data Profile Report")
    ----> 105 profile.to_file("cdap_data_profile_report.html")
    
    File c:\Users\fengq\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas_profiling\profile_report.py:257, in ProfileReport.to_file(self, output_file, silent)
        254         self.config.html.assets_prefix = str(output_file.stem) + "_assets"
        255     create_html_assets(self.config, output_file)
    --> 257 data = self.to_html()
        259 if output_file.suffix != ".html":
        260     suffix = output_file.suffix
    
    File c:\Users\fengq\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas_profiling\profile_report.py:368, in ProfileReport.to_html(self)
        360 def to_html(self) -> str:
        361     """Generate and return complete template as lengthy string
        362         for using with frameworks.
        363 
       (...)
        366 
        367     """
    --> 368     return self.html
    ...
    --> 810 fig = manager.canvas.figure
        811 if fig_label:
        812     fig.set_label(fig_label)
    
    AttributeError: 'NoneType' object has no attribute 'canvas'

I've tried to re-install python and reinstalling the dependencies for pandas-profiling but nothing seems to work so far. I've also tried downgrading python to python 3.9 and the matplotlib to an older version as well. It has not changed this error.

I notice that the error seems to be attributed to "manager.canvas.figure" but I'm not sure how to resolve it from that point onwards. Any help is greatly appreciated!

Adriaan
  • 17,741
  • 7
  • 42
  • 75
AllenFeng
  • 11
  • 2
  • Welcome to Stack Overflow! Please do not add answers to the question body itself. Instead, you should add it as an answer. [Answering your own question is allowed and even encouraged](https://stackoverflow.com/help/self-answer). – Adriaan Aug 18 '22 at 12:19
  • Thank you Adriaan! I will do that. :) Appreciate the heads up! – AllenFeng Aug 19 '22 at 14:14

1 Answers1

1

The problem resolved as I set the matplotlib to inline as per some comments that I was able to find on another forum. I'm still really interested to learn what causes this! Please feel free to answer and suggest other solutions! I would love to try them!

AllenFeng
  • 11
  • 2