sklearn: Getting error while importing sklean in jupyter notebook - python

Importing sklearn gives error in anaconda jupyter notebook. I have installed scikitlearn package and issue is still seen.
Traceback (most recent call last):
File "version.py", line 18, in <module>
import sklearn
File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\__init__.py", line 13
4, in <module>
from .base import clone
File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\base.py", line 13, in
<module>
from .utils.fixes import signature
File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\__init__.py", l
ine 11, in <module>
from .validation import (as_float_array,
File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\validation.py",
line 18, in <module>
from ..utils.fixes import signature
File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\fixes.py", line
144, in <module>
from scipy.sparse.linalg import lsqr as sparse_lsqr # noqa
File "C:\ProgramData\Anaconda3\lib\site-packages\scipy\sparse\linalg\__init__.
py", line 118, in <module>
from .matfuncs import *
File "C:\ProgramData\Anaconda3\lib\site-packages\scipy\sparse\linalg\matfuncs.
py", line 19, in <module>
import scipy.special
File "C:\ProgramData\Anaconda3\lib\site-packages\scipy\special\__init__.py", l
ine 640, in <module>
from ._ufuncs import *
ImportError: DLL load failed: The specified procedure could not be found.
(base) C:\Windows\system32>

As referred in this link that looks similar. You probably dont have c++ windows compiler. You will need to install Visual C++ Redistributable and then reinstalling anaconda might solve the issue.
On a side note anaconda generally takes care of the installing of the c++ compiler. Did you create virtualenv and pip install. I will suggest you install using conda install.
conda install scipy

Related

ImportError: DLL load failed: The specified procedure could not be found. (thinkdsp and thinkplot)

I am an amateur programmer. I am trying to use:
import thinkdsp as dsp
import thinkplot as plt
I have installed the pip install thinkx module but I keep getting that error and I don't understand why. I will leave what the console shows down below:
Traceback (most recent call last):
File "Karaokemaker1.py", line 1, in <module>
import thinkdsp as dsp
File "C:\Users\keigo\anaconda3\lib\site-packages\thinkdsp.py", line 17, in <module>
import scipy.stats
File "C:\Users\keigo\anaconda3\lib\site-packages\scipy\stats\__init__.py", line 384, in <module>
from .stats import *
File "C:\Users\keigo\anaconda3\lib\site-packages\scipy\stats\stats.py", line 185, in <module>
from . import distributions
File "C:\Users\keigo\anaconda3\lib\site-packages\scipy\stats\distributions.py", line 10, in <module>
from ._distn_infrastructure import (entropy, rv_discrete, rv_continuous,
File "C:\Users\keigo\anaconda3\lib\site-packages\scipy\stats\_distn_infrastructure.py", line 25, in <module>
from scipy import optimize
File "C:\Users\keigo\anaconda3\lib\site-packages\scipy\optimize\__init__.py", line 390, in <module>
from ._minimize import *
File "C:\Users\keigo\anaconda3\lib\site-packages\scipy\optimize\_minimize.py", line 30, in <module>
from ._trustregion_constr import _minimize_trustregion_constr
File "C:\Users\keigo\anaconda3\lib\site-packages\scipy\optimize\_trustregion_constr\__init__.py", line 4, in <module>
from .minimize_trustregion_constr import _minimize_trustregion_constr
File "C:\Users\keigo\anaconda3\lib\site-packages\scipy\optimize\_trustregion_constr\minimize_trustregion_constr.py", line 4, in <module>
from scipy.sparse.linalg import LinearOperator
File "C:\Users\keigo\anaconda3\lib\site-packages\scipy\sparse\linalg\__init__.py", line 116, in <module>
from .eigen import *
File "C:\Users\keigo\anaconda3\lib\site-packages\scipy\sparse\linalg\eigen\__init__.py", line 11, in <module>
from .arpack import *
File "C:\Users\keigo\anaconda3\lib\site-packages\scipy\sparse\linalg\eigen\arpack\__init__.py", line 22, in <module>
from .arpack import *
File "C:\Users\keigo\anaconda3\lib\site-packages\scipy\sparse\linalg\eigen\arpack\arpack.py", line 45, in <module>
from . import _arpack
ImportError: DLL load failed: The specified procedure could not be found.
I assumed the issue was with the scipy because all the following errors come from that module. I checked and I have everything installed properly for the scipy module.
Please help! Thank you!
Run any command prompt you are using as administrator and then run pip install lib_name --force-reinstall
Try using these two commands they will help you:
conda remove --force scipy
And:
pip install scipy
Hello I had the same issue than you. Depend on wich version of python you use you should choose a version thinkx. I recommend you to go on the website of thinkx and check out for past udapte. In my case that was with matplotlib 3.3.1 for python 3.7. I went in git bash and used
pip install matplotlib==3.0.1
and everything worked. I had the same issue with seaborn and it worked.

OSError: could not find or load spatialindex_c.dll

I have installed the whl files for fiona, shapely, gdal, rtree and pyproj. Geopandas is also installed via pip install. But I get the following error when importing it:
import geopandas
Traceback (most recent call last):
File "<ipython-input-14-c9ee6bd24dbc>", line 1, in <module>
import geopandas
File "C:\ProgramData\Anaconda3\lib\site-packages\geopandas\__init__.py", line 1, in <module>
from geopandas.geoseries import GeoSeries
File "C:\ProgramData\Anaconda3\lib\site-packages\geopandas\geoseries.py", line 12, in <module>
from geopandas.base import GeoPandasBase, _series_unary_op, _CoordinateIndexer
File "C:\ProgramData\Anaconda3\lib\site-packages\geopandas\base.py", line 14, in <module>
from rtree.core import RTreeError
File "C:\ProgramData\Anaconda3\lib\site-packages\rtree\__init__.py", line 1, in <module>
from .index import Rtree
File "C:\ProgramData\Anaconda3\lib\site-packages\rtree\index.py", line 5, in <module>
from . import core
File "C:\ProgramData\Anaconda3\lib\site-packages\rtree\core.py", line 116, in <module>
raise OSError("could not find or load spatialindex_c.dll")
OSError: could not find or load spatialindex_c.dll
and the following error as well:
import fiona
Traceback (most recent call last):
File "<ipython-input-16-cc872b235141>", line 1, in <module>
import fiona
File "C:\ProgramData\Anaconda3\lib\site-packages\fiona\__init__.py", line 77, in <module>
from fiona.collection import Collection, BytesCollection, vsi_path
File "C:\ProgramData\Anaconda3\lib\site-packages\fiona\collection.py", line 9, in <module>
from fiona.ogrext import Iterator, ItemsIterator, KeysIterator
File "fiona\ogrext.pyx", line 25, in init fiona.ogrext
ImportError: cannot import name compat
Can somebody please help me here?
I'm not being able to figure out how to fix this issue. Thanks and regards.
You could try the installation with conda instead of pip.
conda install -c conda-forge cenpy
See the CenPy documentation: https://pypi.org/project/cenpy/
You don't need to separately install geopandas and Rtree if you use conda.

I can`t import scikit -learn on python3. how can i import it?

I installed numpy-1.13.1+mkl-cp36-cp36m-win32 .whl and scipy-0.19.1-cp36-cp36m-win32.whl successfully, then I installed scikit-learn successfully, but when I ran import sklearn,
pycharm gave me errors. How can I remove this problem?
I installed python3.6 (32bit) on windows 10 (64bit).
import sklearn
result of run:
C:\Users\Emertat\AppData\Local\Programs\Python\Python36-32\python.exe "F:/Python/NS videos/cedes/Exercise 07 test.py"
Traceback (most recent call last):
File "F:/Python/NS videos/cedes/Exercise 07 test.py", line 21, in <module>
import sklearn
File "C:\Users\Emertat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\sklearn\__init__.py", line 134, in <module>
from .base import clone
File "C:\Users\Emertat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\sklearn\base.py", line 12, in <module>
from .utils.fixes import signature
File "C:\Users\Emertat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\sklearn\utils\__init__.py", line 11, in <module>
from .validation import (as_float_array,
File "C:\Users\Emertat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\sklearn\utils\validation.py", line 18, in <module>
from ..utils.fixes import signature
File "C:\Users\Emertat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\sklearn\utils\fixes.py", line 144, in <module>
from scipy.sparse.linalg import lsqr as sparse_lsqr # noqa
File "C:\Users\Emertat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\scipy\sparse\linalg\__init__.py", line 117, in <module>
from .matfuncs import *
File "C:\Users\Emertat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\scipy\sparse\linalg\matfuncs.py", line 19, in <module>
import scipy.special
File "C:\Users\Emertat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\scipy\special\__init__.py", line 640, in <module>
from ._ufuncs import *
ImportError: DLL load failed: The specified procedure could not be found.
Process finished with exit code 1
First, Remove the sklearn form your Windows OS by using the following command-
pip uninstall scikit-learn
Then, you need to install numpy and scipy from their own official installers.
Wheel packages (.whl files) for scikit-learn from pypi can be installed with the pip utility. Open a console and type the following to install or upgrade scikit-learn to the latest stable release:
pip install -U scikit-learn
If there are no binary packages matching your python, version you might to try to install scikit-learn and its dependencies from christoph gohlke unofficial windows installers or from a python distribution instead.

Unable to import python packages in Ubuntu (ImportError : undefined symbol)

I recently installed python on my Ubuntu 14.04. I downloaded tensorflow by pip.
When I tried to import tensorflow it said ImportError:No module named tensorflow.
Then I edited PYTHONPATH by adding /usr/local/lib/python2.7/dist-packages. Now when I try to import, it says
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.py", line 23, in <module>
from tensorflow.python import *
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 45, in <module>
import numpy as np
File "/usr/local/lib/python2.7/dist-packages/numpy/__init__.py", line 180, in <module>
from . import add_newdocs
File "/usr/local/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/local/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/usr/local/lib/python2.7/dist-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/usr/local/lib/python2.7/dist-packages/numpy/core/__init__.py", line 14, in <module>
from . import multiarray
ImportError: /usr/local/lib/python2.7/dist-packages/numpy/core/multiarray.so: undefined symbol: PyUnicodeUCS4_AsUnicodeEscapeString
I found here that 2 versions of python causes the conflict, but that didn't help. Any assistance will be appreciated. Thank you
Best way to install packages if you have more than one python installed is:
path_to_your_python_executable -m pip install package_name
This way, you can make sure that you have installed package for proper python.
And don't forget about sudo ;)

Python Anaconda: ImportError undefined symbol: ATL_cpttrsm

>>> import scipy.stats
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/scipy/stats/__init__.py", line 334, in <module>
from .stats import *
File "/usr/local/lib/python2.7/dist-packages/scipy/stats/stats.py", line 186, in <module>
from . import distributions
File "/usr/local/lib/python2.7/dist-packages/scipy/stats/distributions.py", line 10, in <module>
from ._distn_infrastructure import (entropy, rv_discrete, rv_continuous,
File "/usr/local/lib/python2.7/dist-packages/scipy/stats/_distn_infrastructure.py", line 22, in <module>
from scipy import optimize
File "/usr/local/lib/python2.7/dist-packages/scipy/optimize/__init__.py", line 165, in <module>
from ._root import *
File "/usr/local/lib/python2.7/dist-packages/scipy/optimize/_root.py", line 20, in <module>
from . import nonlin
File "/usr/local/lib/python2.7/dist-packages/scipy/optimize/nonlin.py", line 122, in <module>
import scipy.sparse.linalg
File "/usr/local/lib/python2.7/dist-packages/scipy/sparse/linalg/__init__.py", line 110, in <module>
from .dsolve import *
File "/usr/local/lib/python2.7/dist-packages/scipy/sparse/linalg/dsolve/__init__.py", line 60, in <module>
from .linsolve import *
File "/usr/local/lib/python2.7/dist-packages/scipy/sparse/linalg/dsolve/linsolve.py", line 10, in <module>
from . import _superlu
ImportError: /usr/local/lib/python2.7/dist-packages/scipy/sparse/linalg/dsolve/_superlu.so: undefined symbol: ATL_cpttrsm
Importing scipy.stats gives the error above. I recently installed Python anaconda. I have tried reinstalling numpy and scipy but to no avail. I am using Ubuntu 14.04
The command "which -a python" gives the following lines as output :-
/home/abhishek/anaconda/bin/python
/usr/bin/python
You should unset PYTHONPATH. It is causing your Anaconda Python to pick up packages installed in /usr/local instead of just the Anaconda packages (which should work correctly).
It was pointed out to me that the scipy installation in /usr/local/ was broken and that I needed to uninstall it.
sudo pip uninstall scipy
This fixed the problem.

Categories