Scipy

Attributeerror: module scipy.sparse has no attribute coo_array

attributeerror: module scipy.sparse has no attribute coo_array error occurs if you are running lower version of scipy ( less than v1.8 )   with scipy.sparse.*_array or similar functions. Since this scipy.sparse.*_array or similar functions are part of scipy release 1.8 . Hence if you have lower version of scipy , if will create code incompatibility and throw the same AttributeError.  Sometimes developers do not explicitly invoke scipy.sparse but any other package like networkx etc implicitly invokes it and we get this error.

Attributeerror: module scipy.sparse has no attribute coo_array ( Solutions ) –

To remove this incompatibility we can either upgrade scipy to a version greater than 1.8 or we can downgrade the underline package which is implicitly invoking the scipy. But I will recommend going for option one upgrade. Because lowering any package version may create multiple similar incompatibility errors.  Anyways let’s start the solutioning.

Solution 1: Upgrading scipy version > 1.8 –

1. Generally pip is the first choice for everyone for package management in Python. Here is the command –

pip install scipy==1.8.0

or the current version is 1.10.0 hence –

pip install scipy

2. If you are using the conda then you can try the below one as well.

conda install 'scipy>=1.8'

3. If you want to use the source code then you can download any branch from the git which is greater than 1.8 release and run the below command-

Attributeerror module scipy.sparse has no attribute coo_array git fix
python install setup.py

Solution 2: Downgrading Super package (like networkx) –

Here super packages are those python module which implicitly invoke scipy.sparse. If we downgrade them, It will resolve this error. Just to make it more specific for better understanding if we downgrade the networkx module lower to the 2.7 version ( Version release details networkx)  . we will fix the problem. Here is the command for this.

pip install networkx==2.6.3

Other Similar Errors :

Module ‘scipy’ has no attribute ‘integrate’ ( Solved )

Module ‘scipy’ has no attribute ‘stats’ ( Solved )

Thanks
Data Science Learner Team