error while "from sklearn import datasets" - scikit-learn

from sklearn import datasets
When running the above code, I got an error:
`Traceback` (most recent call last):
File "perceptron_ml.py", line 2, in <module>
from sklearn import datasets
File "/home/remember/.local/lib/python3.6/site-packages/sklearn/datasets/__init__.py", line 22, in <module>
from ._twenty_newsgroups import fetch_20newsgroups
File "/home/remember/.local/lib/python3.6/site-packages/sklearn/datasets/_twenty_newsgroups.py", line 45, in <module>
from ..feature_extraction.text import CountVectorizer
File "/home/remember/.local/lib/python3.6/site-packages/sklearn/feature_extraction/__init__.py", line 8, in <module>
from ._hashing import FeatureHasher
ImportError: cannot import name 'FeatureHasher'
Ubuntu: 18.04, Python: 3.6.9, Numpy: 1.17.4, scikit-learn: 0.22

The error is due to a glitch happening during the update due to pip. Related SO post is https://stackoverflow.com/a/59355676/6513708
But long story short, you need to remove the following files which were let by pip during the update:
~/.local/lib/python3.6/site-packages/sklearn/decomposition/_online_lda.cpython-36m-x86_64-linux-gnu.so
~/.local/lib/python3.6/site-packages/sklearn/feature_extraction/_hashing.cpython-36m-x86_64-linux-gnu.so
~/.local/lib/python3.6/site-packages/sklearn/datasets/_svmlight_format.cpython-36m-x86_64-linux-gnu.so

Related

ModuleNotFoundError: No module named 'scipy.sparse.base'

I'm trying to run from sklearn import preprocessing, but it raise an error:
Traceback (most recent call last):
File "<ipython-input-6-d27a4e3c0526>", line 1, in <module>
from sklearn import preprocessing
File "/Users/x/anaconda3/lib/python3.6/site-packages/sklearn/__init__.py", line 82, in <module>
from .base import clone
File "/Users/x/anaconda3/lib/python3.6/site-packages/sklearn/base.py", line 17, in <module>
from .utils import _IS_32BIT
File "/Users/x/anaconda3/lib/python3.6/site-packages/sklearn/utils/__init__.py", line 20, in <module>
from scipy.sparse import issparse
File "/Users/x/.local/lib/python3.6/site-packages/scipy/sparse/__init__.py", line 227, in <module>
from .base import *
ModuleNotFoundError: No module named 'scipy.sparse.base'
How could I deal with it?
The version of scipy is 1.5.4.
Using pip3 install --upgrade --user scipy solved the problem for me.

ImportError: Importing the multiarray numpy extension module failed

I am trying to write Python script in Java using ScriptEngine. But when I import tflearn module it gives me following errors.
javax.script.ScriptException: ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control). Otherwise reinstall numpy.
Original error was: cannot import name multiarray
in <script> at line number 1
at org.python.jsr223.PyScriptEngine.scriptException(PyScriptEngine.java:222)
at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:59)
at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:31)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
at com.ultimatix.bot.JavaRunCommand.main(JavaRunCommand.java:48)
Caused by: Traceback (most recent call last):
File "<script>", line 1, in <module>
File "D:\Python\Lib\site-packages\tflearn\__init__.py", line 4, in <module>
from . import config
File "D:\Python\Lib\site-packages\tflearn\config.py", line 3, in <module>
import tensorflow as tf
File "D:\Python\Lib\site-packages\tensorflow\__init__.py", line 24, in <module>
from tensorflow.python import *
File "D:\Python\Lib\site-packages\tensorflow\python\__init__.py", line 47, in <module>
import numpy as np
File "D:\Python\Lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "D:\Python\Lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "D:\Python\Lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "D:\Python\Lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "D:\Python\Lib\site-packages\numpy\core\__init__.py", line 26, in <module>
raise ImportError(msg)
I also tried to import some different package like sys, pickle. They are getting imported successfully.
Python version: 3.5.4
OS: Window 7 - 64 bits
Numpy is written in Fortran and compiled to binary. For that reason, it is not compatible to be ran on the JVM. The other packages you are importing are implemented in pure python.
CPython, the standard python implementation, has done a lot of work to stay compatible at the binary level. Numpy arrays have the same memory layout as C arrays, which do not have the same memory layout as Java arrays. As you go deeper into python there are a lot more incompatibilities as to why it won't work.

scipy.stats attribute not found

I tried to import scipy.stats as ss but it keeps showing me an import error:
Traceback (most recent call last):
File "E:\My Python Files\KNN_Classification.py", line 4, in <module>
import scipy.stats
File "D:\Python3.6\lib\site-packages\scipy\stats\__init__.py", line 343, in <module>
from .stats import *
File "D:\Python3.6\lib\site-packages\scipy\stats\stats.py", line 169, in <module>
import scipy.special as special
File "D:\Python3.6\lib\site-packages\scipy\special\__init__.py", line 640, in <module>
from ._ufuncs import *
ImportError: DLL load failed: The specified module could not be found.
What should I do?
Most likely a wrong installation. You should remove the build directory as well as the installed scipy in site-packages, and then reinstall scipy.

Python cannot import name 'NUMPY_MKL'

I am trying to run a wavenet implementation (which uses tensorflow + librosa). However, I keep running into the error "cannot import name 'NUMPY_MKL'".
I have already installed tensorflow, numpy+mk1, scipy and librosa. Tensorflow itself is loading fine, but error is triggered when I run the wavenet implementation which uses librosa.
My spec/details:
Python 3.5.2
Numpy+MK1 (numpy-1.13.1+mkl-cp35-cp35m-win_amd64.whl)
Scipy (scipy-0.19.1-cp35-cp35m-win_amd64.whl)
Windows 10 x64
Nvidia CUDA v8.0 (cudnn 5.1)
Hope you can help. Full error log below:
Traceback (most recent call last):
File "train.py", line 20, in <module>
from wavenet import WaveNetModel, AudioReader, optimizer_factory
File "D:\musicAI\wavenet\__init__.py", line 2, in <module>
from .audio_reader import AudioReader
File "D:\musicAI\wavenet\audio_reader.py", line 7, in <module>
import librosa
File "C:\Python35\lib\site-packages\librosa\__init__.py", line 12, in <module>
from . import core
File "C:\Python35\lib\site-packages\librosa\core\__init__.py", line 108, in <module>
from .time_frequency import * # pylint: disable=wildcard-import
File "C:\Python35\lib\site-packages\librosa\core\time_frequency.py", line 10, in <module>
from ..util.exceptions import ParameterError
File "C:\Python35\lib\site-packages\librosa\util\__init__.py", line 67, in <module>
from .utils import * # pylint: disable=wildcard-import
File "C:\Python35\lib\site-packages\librosa\util\utils.py", line 5, in <module>
import scipy.ndimage
File "C:\Python35\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'
Managed to fixed this by doing a complete uninstall of numpy+mk1, then installing it again.
I was previously doing:
pip install --ignore-install path\numpy.whl
Do this instead to get it working:
pip uninstall numpy # this removes the existing copy
pip install path\numpy.whl # this install the numpy+mk1 from local .whl file

error of import scipy.stats for windows 7

I use windows 7 and installed python 3.5 32bit. I installed numpy 1.11 + mkl win32 whl version for python 3.5 from http://www.lfd.uci.edu/~gohlke/pythonlibs/
and installed scipy 0.17.0 from the same site same way. I use pip install. No problem import numpy and scipy, but see error when import scipy.stats or from scipy import stats, etc... Here is the error message:
if from scipy import stats:
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
from scipy import stats
File "C:\Programs\Python\Python35-32\lib\site-packages\scipy\stats\__init__.py", line 338, in <module>
from .stats import *
File "C:\Programs\Python\Python35-32\lib\site-packages\scipy\stats\stats.py", line 180, in <module>
import scipy.special as special
File "C:\Programs\Python\Python35-32\lib\site-packages\scipy\special\__init__.py", line 627, in <module>
from ._ufuncs import *
File "scipy\special\_ufuncs.pyx", line 1, in init scipy.special._ufuncs (scipy\special\_ufuncs.c:26242)
ImportError: DLL load failed: The specified module could not be found.
If use import scipy.stats see below error message:
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
import scipy.stats
File "C:\Programs\Python\Python35-32\lib\site-packages\scipy\stats\__init__.py", line 338, in <module>
from .stats import *
File "C:\Programs\Python\Python35-32\lib\site-packages\scipy\stats\stats.py", line 180, in <module>
import scipy.special as special
File "C:\Programs\Python\Python35-32\lib\site-packages\scipy\special\__init__.py", line 629, in <module>
from .basic import *
File "C:\Programs\Python\Python35-32\lib\site-packages\scipy\special\basic.py", line 14, in <module>
from ._ufuncs import (ellipkm1, mathieu_a, mathieu_b, iv, jv, gamma, psi, zeta,
ImportError: cannot import name 'ellipkm1'
I have searched for solution from websites but could not find an answer. Please help. This is really frustrating...
Thanks
Rocky
Ok, finally I solved this myself. At the beginning I knew I needed the 2015 visual C++ redistribution and had it installed, the problem is I installed the 64bit one while obviously I should have used 32 bit one since my python and numpy, scipy were all 32 bit.
Hope this helps for other people

Resources