question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AttributeError: module 'scipy' has no attribute 'sparse' in sklearn/utils/fixes.py

See original GitHub issue

Description

I have updated sklearn, scipy (previously all worked fine). As a result, the error started to occur in sklearn\utils\fixes.py:

AttributeError: module 'scipy' has no attribute 'sparse'

I have tried to execute the same import command from fixes.py and it failed with error:

import scipy.sparse as sp 

Following command is working:

from scipy import sparse 

Steps/Code to Reproduce

from sklearn import datasets

iris = datasets.load_iris()

Expected Results

No error is thrown

Actual Results

File "....projects/Test.py", line 8, in <module>
    from sklearn import datasets

  File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\__init__.py", line 64, in <module>
    from .base import clone

  File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\base.py", line 14, in <module>
    from .utils.fixes import signature

  File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\__init__.py", line 16, in <module>
    from .fixes import _Sequence as Sequence

  File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\fixes.py", line 20, in <module>
    import scipy.sparse as sp

AttributeError: module 'scipy' has no attribute 'sparse'

Versions

python: 3.6.8 scikit-learn 0.20.3 numpy: 1.15.4 scipy: 1.2.1 platform: Windows-8.1-6.3.9600-SP0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rjdoubleucommented, Jan 16, 2020

@TatianaParshina what versions are you running? I have the following:

numpy-1.18.1 scikit-learn-0.22.1 scipy-1.4.1

and am receiving the same errors after reinstall.

0reactions
yuslepukhincommented, Oct 26, 2021

I would bet you have called a file scipy.py somewhere in your PYTHONPATH

Yes, I saw earlier posts and checked for that. I just needed to import sparse in addition to scipy.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does this AttributeError in python occur? - Stack Overflow
This happens because the scipy module doesn't have any attribute named sparse . That attribute only gets defined when you import ...
Read more >
module 'scipy' has no attribute 'sparse'
I wrote a function to create a random sparse Matrix. but when I run the code in Pycham, I get following error: C...
Read more >
AttributeError: 'numpy.ndarray' object has no attribute 'fit' [closed]
I am creating a pipeline of custom transformers and get this error: AttributeError: 'numpy.ndarray' object has no attribute 'fit'. Below is the ...
Read more >
Implementing privacy preservation through Python - Kaggle
A short intro to privacy preservation¶. With the ever growing number of datasets being published, there is an increased risk of seeing personal...
Read more >
Date-A-Scientist - Scikit-Learn Import error
C:/Users/Lucas/anaconda3/python.exe "d:/Projetos/Code/Date a ... AttributeError: 'str' object has no attribute 'str'. x.find():.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found