Pandas Profiling Import Error: cannot import name 'soft_unicode' from 'markupsafe'

Viewed 2577

I have an issue with getting started with pandas profiling.

I tried loading pandas profiling, but upon installation this error pops up:

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. anaconda-project 0.9.1 requires ruamel-yaml, which is not installed. sphinx 4.0.1 requires MarkupSafe<2.0, but you have markupsafe 2.1.1 which is incompatible.

I tried to fix it by installing an earlier version. But if I install a MarkupSafe version below 2.0 as indicated, I get the following error:

pandas-profiling 3.2.0 requires markupsafe~=2.1.1, but you have markupsafe 2.0.1 which is incompatible

Now, if I just try to use pandas profiling anyways, I get the error:

cannot import name 'soft_unicode' from 'markupsafe'

This is the code I used:

from pandas_profiling import ProfileReport
import pandas as pd

df = pd.read_excel("WBNAME", sheetname = None)
prof = ProfileReport(df)
prof.to_file(output_file='output.html') 

What exactly should I do here to be able to use pandas profiling?

3 Answers

This is an unfortunate case where things break down when your package code is being used by other software as a dependency, and you cannot foresee/test all use cases.

This worked for me:

!pip uninstall markupsafe
!pip install markupsafe==2.0.1

Then, if using a notebook, restart and import pandas-profiling.

Rationale: reinstalling a previous version of markupsafe that still supports soft_unicode will throw this error:

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. 
pandas-profiling 3.2.0 requires markupsafe~=2.1.1, but you have markupsafe 2.0.1 which is incompatible.

But, the line after still says:

Successfully installed markupsafe-2.0.1

So, good2go.

Try below lines, maybe it works

import pandas_profiling as pp
df = pd.read_excel("WBNAME", sheetname = None)
profile= pp.ProfileReport(df)
profile.to_file('pandas_profile_test.html')

Before you install your extension, just use the below commands:

pip install h5py
pip install typing-extensions
pip install wheel

and then install your extension. This worked for me.

Referred from this page: https://github.com/apple/turicreate/issues/3383

Related