Cannot import Scikit-Learn - python

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

Related

ERROR: No matching distribution found for jaxlib==0.1.67

I need jaxlib==0.1.67 for a project I'm working on, but I can't
downgrade. At the moment I have jaxlib==0.1.75 and my program keeps failing due to an error I can't find a solution to either. I compared all versions of the important packages to another machines versions where my programs runs with no problems and the only difference is the jaxlib version (it's still 0.1.67 on the machine where it runs). I suspect that jaxlib is the issue because the error I get when it's not 0.1.67 is the following:
from haiku import data_structures
File "/net/home/justen/.local/lib/python3.10/site-packages/haiku/data_structures.py", line 17, in <module>
from haiku._src.data_structures import to_immutable_dict
File "/net/home/justen/.local/lib/python3.10/site-packages/haiku/_src/data_structures.py", line 30, in <module>
from haiku._src import utils
File "/net/home/justen/.local/lib/python3.10/site-packages/haiku/_src/utils.py", line 24, in <module>
import jax
File "/net/home/justen/.local/lib/python3.10/site-packages/jax/__init__.py", line 108, in <module>
from .experimental.maps import soft_pmap
File "/net/home/justen/.local/lib/python3.10/site-packages/jax/experimental/maps.py", line 25, in <module>
from .. import numpy as jnp
File "/net/home/justen/.local/lib/python3.10/site-packages/jax/numpy/__init__.py", line 16, in <module>
from . import fft
File "/net/home/justen/.local/lib/python3.10/site-packages/jax/numpy/fft.py", line 17, in <module>
from jax._src.numpy.fft import (
File "/net/home/justen/.local/lib/python3.10/site-packages/jax/_src/numpy/fft.py", line 19, in <module>
from jax import lax
File "/net/home/justen/.local/lib/python3.10/site-packages/jax/lax/__init__.py", line 334, in <module>
from jax._src.lax.parallel import (
File "/net/home/justen/.local/lib/python3.10/site-packages/jax/_src/lax/parallel.py", line 36, in <module>
from jax._src.numpy import lax_numpy
File "/net/home/justen/.local/lib/python3.10/site-packages/jax/_src/numpy/lax_numpy.py", line 51, in <module>
from jax import ops
File "/net/home/justen/.local/lib/python3.10/site-packages/jax/ops/__init__.py", line 16, in <module>
from jax._src.ops.scatter import (
File "/net/home/justen/.local/lib/python3.10/site-packages/jax/_src/ops/scatter.py", line 31, in <module>
from typing import EllipsisType
ImportError: cannot import name 'EllipsisType' from 'typing' (/usr/lib/python3.10/typing.py)
haiku and typing are the same version on both machines so guess it must be jaxlib. On both machines I'm on pip==20.0.2 and in a python 3.9.9 virtualenv.
When I try to downgrade to jaxlib==0.1.67 I get:
ERROR: Could not find a version that satisfies the requirement jaxlib==0.1.67 (from versions: 0.1.75, 0.1.76, 0.3.0, 0.3.2, 0.3.5, 0.3.7, 0.3.10, 0.3.14, 0.3.15)
ERROR: No matching distribution found for jaxlib==0.1.67
I even tried pip install jaxlib==0.1.67 -f https://storage.googleapis.com/jax-releases/jax_releases.html and it doesn't work.
Has anyone experienced the same problem or maybe has a clue of what could be the issue here to help me?
Based on the path in the exception (/usr/lib/python3.10), it looks like you are using python 3.10. There are no python 3.10 wheels for jaxlib==0.1.67 (see pypi). You will have to use python 3.6-3.9.
If you think you are using python 3.9, then here's a way to clear up confusion when installing packages. Use
python3.9 -m pip install
to install packages into your python 3.9 environment. Replace python3.9 with whichever python interpreter you want to use.
The answer by #jkr is the correct answer for your question as written (how to install jaxlib 0.1.67), but I don't think it will fix the initial error you reported.
This looks like a Python 3.10 only bug that briefly existed in the JAX source code on October 5, 2021, but was fixed and never actually made it into a jax release. If you're seeing this, I suspect it means you installed/imported JAX from unreleased source. Further, installing a different version of jaxlib will not fix this error, because the code is in jax itself. If you're using jaxlib 0.1.75, you might try installing jax v0.2.7 or v0.2.8, which were released around the same time, and shouldn't contain the problematic EllipsisType import.
Another potential issue: you reported using a Python 3.9.9 virtualenv, but your traceback indicates you're executing Python 3.10, so you probably need to check your executable paths to make sure you're executing what you think you are.

Error importing sklearn

Python version : 3.5.2
I getting started with machine learning and things... So I installed sklearn and some other packages form pip. All of them were able to be installed successfully except sklearn so, I downloaded the wheel and installed it from here. It was successfully installed but when i tried to import it in the order to check correct installation, I got tons of error :
Traceback (most recent call last):
File "C:\MyFiles\Programs\Python\PlayGround.py", line 1, in
import sklearn
File "C:\Users\Vaibhav Acharya\AppData\Local\Programs\Python\Python35\lib\site-packages\sklearn__init__.py", line 134, in
from .base import clone
File "C:\Users\Vaibhav Acharya\AppData\Local\Programs\Python\Python35\lib\site-packages\sklearn\base.py", line 12, in
from .utils.fixes import signature
File "C:\Users\Vaibhav Acharya\AppData\Local\Programs\Python\Python35\lib\site-packages\sklearn\utils__init__.py", line 11, in
from .validation import (as_float_array,
File "C:\Users\Vaibhav Acharya\AppData\Local\Programs\Python\Python35\lib\site-packages\sklearn\utils\validation.py", line 18, in
from ..utils.fixes import signature
File "C:\Users\Vaibhav Acharya\AppData\Local\Programs\Python\Python35\lib\site-packages\sklearn\utils\fixes.py", line 144, in
from scipy.sparse.linalg import lsqr as sparse_lsqr # noqa
File "C:\Users\Vaibhav Acharya\AppData\Local\Programs\Python\Python35\lib\site-packages\scipy\sparse\linalg__init__.py", line 114, in
from .isolve import *
File "C:\Users\Vaibhav Acharya\AppData\Local\Programs\Python\Python35\lib\site-packages\scipy\sparse\linalg\isolve__init__.py", line 6, in
from .iterative import *
File "C:\Users\Vaibhav Acharya\AppData\Local\Programs\Python\Python35\lib\site-packages\scipy\sparse\linalg\isolve\iterative.py", line 7, in
from . import _iterative
ImportError: DLL load failed: The specified module could not be found.
And the code was just :
import sklearn
I have already checked correct version of wheel package which, I have downloaded.
How can I correct it and why it is occurring?
The following steps solved my problem :
Uninstalling numpy, sklearn and scipy.
Downloading numpy+mkl and scipy from here.
Firstly installing numpy+mkl and then scipy.
Installing sklearn from pip.
Various things need to be checked:
Check numpy, scipy installation versions.
If they are correct then try to import numpy and scipy.
If they getting imported correctly, then clear your temp(c:/users/username/Appdata/local/temp)folder. Restart the machine and try again.
Still if doesn't work, then uninstall scipy, numpy , sklearn and
reinstall the proper wheel files
Download and install numpy+mkl file.
Currently you might have installed only the numpy file.
Go to: https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
Download the corresponding wheel file in which is suitable for your python installation
pip install "/path_to_thefile/numpy-1.14.6+mkl-cp36-cp36m-win_amd64.whl"
This should help you

Python 3.5 (32-bit): ImportError: cannot import name NUMPY_MKL

I am new to Python and I am trying to install numpy+mkl and scipy (in the same order), but I get below error when I execute following steps:
import pandas as pd
import numpy as np
from sklearn.preprocessing import LabelEncoder
I am using Python 3.5 (32-bit) on a Windows 7 64-bit OS.
There is a similar question already answered for the exact problem here: ImportError: cannot import name NUMPY_MKL
Going through the answer, I reinstalled my numpy+mkl pkg numpy‑1.11.2+mkl‑cp35‑cp35m‑win32.whl from the mentioned link (http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy) and then reinstalled scipy-0.18.1-cp35-cp35m-win32.whl as well, but that does not solve the problem and I still get the same error:
>>> exec(open("C:\\PythonFiles\\testpy1.py").read())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 3, in <module>
File "C:\Users\msoudagar\AppData\Local\Programs\Python\Python3532\lib\site-packages\sklearn\__init__.py", line 57, in <module>
from .base import clone
File "C:\Users\msoudagar\AppData\Local\Programs\Python\Python35-32\lib\site-packages\sklearn\base.py", line 10, in <module>
from scipy import sparse
File "C:\Users\msoudagar\AppData\Local\Programs\Python\Python3532\lib\site-packages\scipy\__init__.py", line 61, in <module>
from numpy._distributor_init import NUMPY_MKL # requires numpy+mkl
ImportError: cannot import name 'NUMPY_MKL'
Any inputs would be really helpful!
Try commenting out the line
from numpy._distributor_init import NUMPY_MKL
it might just work regardless.
ImportError: cannot import name NUMPY_MKL
I know this is not the most sophisticated of solutions but, all I had to do was close the IDE(in my case, Pycharm) and re-open it again.
Not sophisticated but effective in my case :).
Check this answer. Solved my problem.
https://stackoverflow.com/a/37294205/2708266
Suggesting to download ready made binary setup from http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
pip install xx.whl
I ran into the same issue on Windows with Python 3.5 64 bit. Manually installing numpy+mkl from wheel file solved the issue for me.
Select the appropriate wheel file from here (cp35,win32 for you): and install it using pip install --user Path_to_local_file.whl replacing Path_to_local_file with wherever you saved the .whl file
This is a also a duplicate of ImportError: cannot import name NUMPY_MKL

Import errors after upgrading to sklearn 0.15

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.

Installing numpy broke NLTK (OS X 10.6.2, Python 2.6)

I had a working installation of NLTK (py26-nltk) on my Mac (OS X 10.6.2). Then I installed numpy. Now when I try to import nltk, I get this:
>>> import nltk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "nltk/__init__.py", line 83, in <module>
from collocations import *
File "nltk/collocations.py", line 39, in <module>
from nltk.metrics import ContingencyMeasures, BigramAssocMeasures, TrigramAssocMeasures
File "nltk/metrics/__init__.py", line 14, in <module>
from scores import *
File "nltk/metrics/scores.py", line 15, in <module>
from scipy.stats.stats import betai
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scipy/stats/__init__.py", line 7, in <module>
from stats import *
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scipy/stats/stats.py", line 203, in <module>
from morestats import find_repeats #is only reference to scipy.stats
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scipy/stats/morestats.py", line 7, in <module>
import distributions
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scipy/stats/distributions.py", line 27, in <module>
import vonmises_cython
File "numpy.pxd", line 30, in scipy.stats.vonmises_cython (scipy/stats/vonmises_cython.c:2939)
ValueError: numpy.dtype does not appear to be the correct type object
What has gone wrong? How can I fix this?
It seems to be more of a matter of [version] incompatibility between SciPy and NumPy versions than between NLTK and Numpy.
While SciPy is not required for NLTK, it is an optional import, and will load if available.
A few hypothesis regarding your situation:
Hyp #1
you formerly were running under NumPy 1.3 along with a compatible version of SciPy
you recently installed NumPy 1.4 but didn't touch SciPy
==> "Old" SciPy is broken.
Remedy : Install newer SciPy or uninstall it altogether (although you may be using/needing SciPy, without knowing it, depending on the modules of NLTK you use)
Alternate Remedy: re-install NumPy 1.3 over 1.4.
Hyp #2 (less likely)
You never had SciPy and NLTK was happy, working without it.
You recently installed NumPy 1.4 (over 1.3) and SciPy (over nothing)
For some reason NumPy and SciPy don't play nice together
Remedy: Uninstall SciPy
I had the same problem on Python 2.6 on Windows XP and as suggested by mjv, I uninstalled my old SciPy module and installed the latest, at which stage I got the error that the yaml module was missing.
After installing the PyYAML module, the "import nltk" statement didn't give any errors.
Hope this helps anyone else having the same problem.
Atish
Chiming in somewhat late, but I ran into this problem with numpy and fisher, on osx (snow leopard,
but I assume this would happen on other x86 machines).
I had installed fisher via pypm, and installed numpy from a binary dmg. In a situation
like this I assume that somewhere along the way a binary got infected with a PowerPC
binary, so it's best to clear them away, and rebuild from source.
I manually deleted them from ~/Library/...,
pulled down the sources (including scipy, might as well bite that bullet now),
recompiled all three from source, and two hours later had a working system.

Categories