Date-A-Scientist - Scikit-Learn Import error

Hello there everyone! I’m getting such a strange error while doing Date-A-Scientist. If I try to import sklearn.linear_model.LinearRegression, I get the error below. It’s my first time working with it sklearn off platform and doing some research, it seems like it’s a file error, I’d just like to check in here if there is some issue on that and maybe start a resourceful thread.

$ C:/Users/Lucas/anaconda3/python.exe "d:/Projetos/Code/Date a Scientist/dating_skeleton.py"
Traceback (most recent call last):
  File "d:/Projetos/Code/Date a Scientist/dating_skeleton.py", line 4, in <module>
    from sklearn.linear_model import LinearRegression
  File "C:\Users\Lucas\anaconda3\lib\site-packages\sklearn\__init__.py", line 80, in <module>
    from .base import clone
  File "C:\Users\Lucas\anaconda3\lib\site-packages\sklearn\base.py", line 21, in <module>
    from .utils import _IS_32BIT
  File "C:\Users\Lucas\anaconda3\lib\site-packages\sklearn\utils\__init__.py", line 23, in <module>
    from .class_weight import compute_class_weight, compute_sample_weight
  File "C:\Users\Lucas\anaconda3\lib\site-packages\sklearn\utils\class_weight.py", line 7, in <module>
    from .validation import _deprecate_positional_args
  File "C:\Users\Lucas\anaconda3\lib\site-packages\sklearn\utils\validation.py", line 25, in <module>
    from .fixes import _object_dtype_isnan, parse_version
  File "C:\Users\Lucas\anaconda3\lib\site-packages\sklearn\utils\fixes.py", line 18, in <module>
    import scipy.stats
  File "C:\Users\Lucas\anaconda3\lib\site-packages\scipy\stats\__init__.py", line 388, in <module>
    from .stats import *
  File "C:\Users\Lucas\anaconda3\lib\site-packages\scipy\stats\stats.py", line 180, in <module>
    from . import distributions
  File "C:\Users\Lucas\anaconda3\lib\site-packages\scipy\stats\distributions.py", line 8, in <module>
    from ._distn_infrastructure import (entropy, rv_discrete, rv_continuous,
  File "C:\Users\Lucas\anaconda3\lib\site-packages\scipy\stats\_distn_infrastructure.py", line 23, in <module>
    from scipy import optimize
  File "C:\Users\Lucas\anaconda3\lib\site-packages\scipy\optimize\__init__.py", line 387, in <module>
    from .optimize import *
  File "C:\Users\Lucas\anaconda3\lib\site-packages\scipy\optimize\optimize.py", line 36, in <module>
    from ._numdiff import approx_derivative
  File "C:\Users\Lucas\anaconda3\lib\site-packages\scipy\optimize\_numdiff.py", line 6, in <module>
    from scipy.sparse.linalg import LinearOperator
  File "C:\Users\Lucas\anaconda3\lib\site-packages\scipy\sparse\linalg\__init__.py", line 114, in <module>
    from .eigen import *
  File "C:\Users\Lucas\anaconda3\lib\site-packages\scipy\sparse\linalg\eigen\__init__.py", line 9, in <module>
    from .arpack import *
  File "C:\Users\Lucas\anaconda3\lib\site-packages\scipy\sparse\linalg\eigen\arpack\__init__.py", line 20, in <module>
    from .arpack import *
  File "C:\Users\Lucas\anaconda3\lib\site-packages\scipy\sparse\linalg\eigen\arpack\arpack.py", line 43, in <module>
    from . import _arpack
ImportError: DLL load failed while importing _arpack:

I found this which might be helpful(?). You might have to uninstall conda versions and install pip versions of scipy.

https://github.com/conda/conda/issues/6396

Or, this from StackOverflow:
https://stackoverflow.com/questions/54083514/how-to-fix-importerror-dll-load-failed-the-specified-procedure-could-not-be-f

1 Like

Hey Lisa!!

Thank you very much!
I tried uninstalling and installing through pip before, but I actually had to conda uninstall scikit-learn, numpy and scipy. So my recommended commands would be.

conda uninstall scikit-learn numpy scipy
conda remove --force scikit-learn numpy scipy
pip uninstall scikit-learn numpy scipy
pip install -U scikit-learn numpy scipy --user

If it’s somehow unnecessary or dangerous, I’ll edit out!

1 Like

You’re welcome.

Wait, so uninstalling conda versions and installing pip versions doesn’t work?
Did you update pip?

I’m not very familiar with that error though… :thinking:

it did! it did. I just tried getting rid of every version possible of each module in my pc then reinstalled everything.

1 Like

Excellent! :partying_face:
I had forgotten to ask if you had a Mac or PC.

I don’t know if this was the explicit reason but try and avoid mixing packages installed with conda and with pip where possible. If you’re using conda for obtaining packages and environment management then get your packages from conda wherever possible and install any additions through pip last and only if you have to (i.e. there’s no build from conda).

A little info on mixing the two here- https://docs.conda.io/projects/conda/en/latest/user-guide/configuration/pip-interoperability.html

2 Likes

HA! I forgot to mention that too. Good thinkin’!
:slight_smile:

This is actually great info! Should be lying somewhere around here!
Which one do you prefer? Which one is a more permanent solution as in installing a package once and not having to do anything about it again?

It’s worth noting that there’s no direct equivalence between *conda and pip as they do vastly different things (there’s numerous online discussions about this if you wanted to look into it). See this recent post by @el_cocodrilo for a little more information: Setting Up Conda in Git Bash and have a read of the page on conda myths linked within this post under ‘What is Conda…’ .

Personally I’d boil it down to this; if conda covers all your requirements, then you may as well use it (unless you really disliked it). It performs many different tasks that would require otherwise require several pieces of software to do the same thing. If you have the time it’s worth trying your hand with the alternative to see what the benefits and drawbacks are but there’s plenty of online discussion about the same if you wanted to look into it. Might save you some time to see what other more experienced folk think.

3 Likes