Import errors after upgrading to sklearn 0.15 - python

Using Ubuntu 13.10 64 bit and python 2.7.5. I've been using sklearn 0.14 for quite some time. After upgrading to version 0.15 via:
pip install --upgrade scikit-learn
I've encountered the following:
from sklearn import svm
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "sklearn/svm/__init__.py", line 13, in <module>
from .classes import SVC, NuSVC, SVR, NuSVR, OneClassSVM, LinearSVC
File "sklearn/svm/classes.py", line 1, in <module>
from .base import BaseLibLinear, BaseSVC, BaseLibSVM
File "sklearn/svm/base.py", line 9, in <module>
from . import libsvm_sparse
File "libsvm_sparse.pyx", line 5, in init sklearn.svm.libsvm_sparse (sklearn/svm/libsvm_sparse.c:6773)
File "sklearn/utils/__init__.py", line 11, in <module>
from .validation import (as_float_array, check_arrays, safe_asarray,
File "sklearn/utils/validation.py", line 17, in <module>
from .fixes import safe_copy
File "sklearn/utils/fixes.py", line 18, in <module>
from .testing import ignore_warnings
File "sklearn/utils/testing.py", line 36, in <module>
from nose.tools import assert_equal
ImportError: No module named nose.tools
Then, if I try again -
from sklearn import svm
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "sklearn/svm/__init__.py", line 13, in <module>
from .classes import SVC, NuSVC, SVR, NuSVR, OneClassSVM, LinearSVC
File "sklearn/svm/classes.py", line 1, in <module>
from .base import BaseLibLinear, BaseSVC, BaseLibSVM
File "sklearn/svm/base.py", line 8, in <module>
from . import libsvm, liblinear
ImportError: cannot import name libsvm
Importing sklearn itself does not raise ImportErrors.
Other answers to similar questions suggested uninstalling and re-installing, which helped others, but not in my case.
Edit:
after uninstalling and re-installing several times, including uninstalling and re-installing scikit-image, the problem seems to have passed, or at least change.
I now get the following:
from sklearn import svm
/usr/local/lib/python2.7/dist-packages/scipy/stats/_continuous_distns.py:24: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility
from . import vonmises_cython
/usr/local/lib/python2.7/dist-packages/scipy/stats/stats.py:188: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility
from ._rank import rankdata, tiecorrect
/usr/local/lib/python2.7/dist-packages/scipy/interpolate/interpolate.py:28: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility
from . import _ppoly
/usr/local/lib/python2.7/dist-packages/scipy/spatial/__init__.py:90: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility
from .ckdtree import *
/usr/local/lib/python2.7/dist-packages/scipy/spatial/__init__.py:91: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility
from .qhull import *
(I am using numpy 1.8.1)
However, other than the warnings, things look like they are working.
I don't know what caused the problem, or what amended it. Maybe installing sklearn first, and then skimage...
Edit 2:
Problem has been solved by completely removing scipy and numpy (including manually removing them from /usr/local/lib/python2.7/dist-packages/ and /usr/share/pyshared/).

It seems something is wrong with the dependency packages when installing scikitlearn (although it didn't happen before for me too). I installed nose by running
pip install nose
and the error went away. Hope this helps.

Related

Facing error messages when importing sklearn in python i.d

I get an error when importing sklearn in python 3.9.
I am using I.D.L.E. in Windows.
Installed it using cmd command: pip install -U scikit-learn as given in https://scikit-learn.org/stable/install.html
The received error message is:
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
import sklearn
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\__init__.py", line 82, in <module>
from .base import clone
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\base.py", line 17, in <module>
from .utils import _IS_32BIT
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\utils\__init__.py", line 29, in <module>
from .fixes import parse_version, threadpool_info
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\utils\fixes.py", line 19, in <module>
import scipy.stats
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\scipy\stats\__init__.py", line 453, in <module>
from ._stats_py import *
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\scipy\stats\_stats_py.py", line 38, in <module>
from scipy.spatial.distance import cdist
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\scipy\spatial\__init__.py", line 104, in <module>
from ._qhull import *
ImportError: DLL load failed while importing _qhull: The specified module could not be found.
Please help.
Since the required file _qhull.yp39-win_amd64.pyd is there, it must be a problem with the dependencies this DLL file has and can't find on your computer.
Use a dependency walker like this one to find out what is missing on your system and see that you get those missing pieces installed.
Quite likely you are missing some of the Microsoft Redistributable Visual Studio Files.
Apparently my scipy got corrupted somehow. Uninstalling and re-installing it fixed the problem. Thanks everyone who took their time and effort to help though.

How to fix error "'module' has no attribute '__version__'" with statsmodels package?

I am trying to use the "statsmodels" package. When I try to import the package using this command:
import statsmodels
it works perfectly but when I tried to run the following comand in Python 2:
from statsmodels.distributions.empirical_distribution import ECDF
I will get the following error:
Traceback (most recent call last):
File "circleseq/circleseq.py", line 16, in <module>
import findCleavageSites
File "/mnt/data/users/S.Sie/circleseq/circleseq-master/circleseq/findCleavageSites.py", line 8, in <module>
from statsmodels.distributions.empirical_distribution import ECDF
File "/usr/lib64/python2.7/site-packages/statsmodels/distributions/__init__.py", line 1, in <module>
from statsmodels.tools._testing import PytestTester
File "/usr/lib64/python2.7/site-packages/statsmodels/tools/__init__.py", line 1, in <module>
from .tools import add_constant, categorical
File "/usr/lib64/python2.7/site-packages/statsmodels/tools/tools.py", line 8, in <module>
from statsmodels.compat.python import lzip, lmap
File "/usr/lib64/python2.7/site-packages/statsmodels/compat/__init__.py", line 1, in <module>
from statsmodels.tools._testing import PytestTester
File "/usr/lib64/python2.7/site-packages/statsmodels/tools/_testing.py", line 11, in <module>
from statsmodels.compat.pandas import assert_equal
File "/usr/lib64/python2.7/site-packages/statsmodels/compat/pandas.py", line 4, in <module>
import numpy as np
File "/usr/lib64/python2.7/site-packages/statsmodels/compat/numpy.py", line 46, in <module>
NP_LT_114 = LooseVersion(np.__version__) < LooseVersion('1.14')
AttributeError: 'module' object has no attribute '__version__'
I have to work with Python 2 since the tool I am using is in Python 2. How I can fix the issue?
Since you only work on Python 2, is it possible to rollback statsmodels where it was compatible to Python 2? You may lost some features, but you can check yourself if the older version is enough to fill in your requirements.
To rollback to an older version of a package, you can add the -I flag to your pip install.
pip install -I <package>==<version>

Import librosa gives "no module named numba.decorators", how to solve?

I installed librosa, and now im trying to import it
import librosa
This throws me this error for some reason
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Asish nayak\AppData\Local\Programs\Python\Python38-32\lib\site-packages\librosa\__init__.py", line 12, in <module>
from . import core
File "C:\Users\Asish nayak\AppData\Local\Programs\Python\Python38-32\lib\site-packages\librosa\core\__init__.py", line 125, in <module>
from .time_frequency import * # pylint: disable=wildcard-import
File "C:\Users\Asish nayak\AppData\Local\Programs\Python\Python38-32\lib\site-packages\librosa\core\time_frequency.py", line 11, in <module>
from ..util.exceptions import ParameterError
File "C:\Users\Asish nayak\AppData\Local\Programs\Python\Python38-32\lib\site-packages\librosa\util\__init__.py", line 77, in <module>
from .utils import * # pylint: disable=wildcard-import
File "C:\Users\Asish nayak\AppData\Local\Programs\Python\Python38-32\lib\site-packages\librosa\util\utils.py", line 15, in <module>
from .decorators import deprecated
File "C:\Users\Asish nayak\AppData\Local\Programs\Python\Python38-32\lib\site-packages\librosa\util\decorators.py", line 9, in <module>
from numba.decorators import jit as optional_jit
ModuleNotFoundError: No module named 'numba.decorators'
Why am i getting this error even after installing the library?
You have to install numbra version 0.48 because of a bug, run
pip install numba==0.48
Librosa Issue on Github
You need to use any numba version before 0.8.0
However, the most recent librosa is not compatible with any numba below 0.48.
At least, that's what I've found from using it on Windows. My solution was to use google colaboratory as it didn't give me any error when importing librosa.
I've got the exact error. Solved it with
pip uninstall --yes librosa
pip install librosa --force-reinstall
Your python version should be 3.8.

DLL Load Failed: The specified module could not be found [Python]

Not sure what the issue is...
...but many of the classifiers will not work on my machine now.
I just installed version 14.1 of scikit-learn. Could this be a path thing?
Traceback (most recent call last):
File "hashtag.py", line 19, in <module>
from sklearn.linear_model import SGDClassifier
File "C:\Anaconda\lib\site-packages\scikit_learn-0.14.1-py2.7-win-amd64.egg\sk
learn\linear_model\__init__.py", line 24, in <module>
from .logistic import LogisticRegression
File "C:\Anaconda\lib\site-packages\scikit_learn-0.14.1-py2.7-win-amd64.egg\sk
learn\linear_model\logistic.py", line 5, in <module>
from ..svm.base import BaseLibLinear
File "C:\Anaconda\lib\site-packages\scikit_learn-0.14.1-py2.7-win-amd64.egg\sk
learn\svm\__init__.py", line 13, in <module>
from .classes import SVC, NuSVC, SVR, NuSVR, OneClassSVM, LinearSVC
File "C:\Anaconda\lib\site-packages\scikit_learn-0.14.1-py2.7-win-amd64.egg\sk
learn\svm\classes.py", line 1, in <module>
from .base import BaseLibLinear, BaseSVC, BaseLibSVM
File "C:\Anaconda\lib\site-packages\scikit_learn-0.14.1-py2.7-win-amd64.egg\sk
learn\svm\base.py", line 8, in <module>
from . import libsvm, liblinear
**ImportError: DLL load failed: The specified module could not be found.**
C:\Users\Owner>
Thank you in advance with your help.
I fixed this with
pip install scipy -U
Maybe there is a bug in the conda recipe / package. You can try to update conda and anaconda with:
conda update conda # update the updater :)
conda update anaconda
If that does not work fix the issue, you can also try:
conda remove scikit-learn
conda install scikit-learn

Cannot import Scikit-Learn

I tried to install scikit-learn on my Linux Mint 12 but failed. I downloaded the package from http://pypi.python.org/pypi/scikit-learn/ and installed with
sudo python2.7 setup.py install
I then changed the directory to home and started python2.7 shell. On importing sklearn I got:
>>> import sklearn
/usr/lib/python2.7/dist-packages/scipy/spatial/__init__.py:7: RuntimeWarning:
numpy.dtype size changed, may indicate binary incompatibility
from ckdtree import *
/usr/lib/python2.7/dist-packages/scipy/spatial/__init__.py:7: RuntimeWarning:
numpy.ndarray size changed, may indicate binary incompatibility
from ckdtree import *
/usr/lib/python2.7/dist-packages/scipy/spatial/__init__.py:7: RuntimeWarning:
numpy.ufunc size changed, may indicate binary incompatibility
from ckdtree import *
/usr/lib/python2.7/dist-packages/scipy/spatial/__init__.py:8: RuntimeWarning:
numpy.dtype size changed, may indicate binary incompatibility
from qhull import *
/usr/lib/python2.7/dist-packages/scipy/spatial/__init__.py:8: RuntimeWarning:
numpy.ndarray size changed, may indicate binary incompatibility
from qhull import *
/usr/lib/python2.7/dist-packages/scipy/spatial/__init__.py:8: RuntimeWarning:
numpy.ufunc size changed, may indicate binary incompatibility
from qhull import *
I think the problem is with scipy's spatial. This is because when I do
>>> from scipy import spatial
I get the same error that I get for Scikit-learn.
Please help.
Thank You.
EDIT: New error.
>>> import sklearn
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/scikit_learn-0.12_git-py2.7-linux-
x86_64.egg/sklearn/__init__.py", line 17, in <module>
from .base import clone
File "/usr/local/lib/python2.7/dist-packages/scikit_learn-0.12_git-py2.7-linux-
x86_64.egg/sklearn/base.py", line 11, in <module>
from .metrics import r2_score
File "/usr/local/lib/python2.7/dist-packages/scikit_learn-0.12_git-py2.7-linux-
x86_64.egg/sklearn/metrics/__init__.py", line 6, in <module>
from .metrics import confusion_matrix, roc_curve, auc, precision_score, \
File "/usr/local/lib/python2.7/dist-packages/scikit_learn-0.12_git-py2.7-linux-
x86_64.egg/sklearn/metrics/metrics.py", line 17, in <module>
from ..utils import check_arrays
File "/usr/local/lib/python2.7/dist-packages/scikit_learn-0.12_git-py2.7-linux-
x86_64.egg/sklearn/utils/__init__.py", line 9, in <module>
from .murmurhash import murmurhash3_32
File "numpy.pxd", line 174, in init sklearn.utils.murmurhash (sklearn/utils
/murmurhash.c:4776)
ValueError: numpy.ndarray has the wrong size, try recompiling
I'm not really sure, but according to this that error happens when a package that depends on numpy is compiled targeting a specific version (or a specific platform), and that package is then installed in a different environment. How did you install those two packages? (numpy and scipy)
I'd suggest uninstalling both and then reinstalling SciPy, either using pip or from source.
I ran into this today on OS X El Capitan. Unfortunately, reinstalling/installing didn't work, since the problem ended up being that numpy installation native to OS X was preferred over the one being installed by pip.
I was able to solve this by following the guidance in: https://apple.stackexchange.com/a/223163
In particular, I used the approach of fixing the python path to prefer pip libraries over OS X native libraries:
Create a file called fix_mac_path.pth in /Library/Python/2.7/site-packages that has the following:
import sys; std_paths=[p for p in sys.path if p.startswith('/System/')]; sys.path=[p for p in sys.path if not p.startswith('/System/')]+std_paths
i was having the exact same problem. I managed to make it work by installing the windows binary for 64 bit windows from http://www.lfd.uci.edu/~gohlke/pythonlibs/#scikit-learn . Hope this works for you

Categories