Python "from sklearn import svm" leads to SyntaxError - python

I am running Python 3.7.0 on macOS, and I have scikit-learn version 0.20.1 installed using pip. I also have numpy and scipy installed.
When I try the following code:
from sklearn import svm
I get the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.7/site-packages/sklearn/svm/__init__.py", line 13, in <module>
from .classes import SVC, NuSVC, SVR, NuSVR, OneClassSVM, LinearSVC, \
File "/usr/local/lib/python3.7/site-packages/sklearn/svm/classes.py", line 4, in <module>
from .base import _fit_liblinear, BaseSVC, BaseLibSVM
File "/usr/local/lib/python3.7/site-packages/sklearn/svm/base.py", line 11, in <module>
from ..preprocessing import LabelEncoder
File "/usr/local/lib/python3.7/site-packages/sklearn/preprocessing/__init__.py", line 6, in <module>
from ._function_transformer import FunctionTransformer
File "/usr/local/lib/python3.7/site-packages/sklearn/preprocessing/_function_transformer.py", line 5, in <module>
from ..utils.testing import assert_allclose_dense_sparse
File "/usr/local/lib/python3.7/site-packages/sklearn/utils/testing.py", line 54, in <module>
from nose.tools import raises as _nose_raises
File "/Library/Python/2.7/site-packages/nose/__init__.py", line 1, in <module>
from nose.core import collector, main, run, run_exit, runmodule
File "/Library/Python/2.7/site-packages/nose/core.py", line 153
print "%s version %s" % (os.path.basename(sys.argv[0]), __version__)
^
SyntaxError: invalid syntax
If i just import sklearn (without specifying svm), I get no errors.
Can I get help with this error please?

Related

ImportError: cannot import name 'Type' when importing 'gensim"

I want to import the "genism" library. I have previously successfully installed it by typing the following in the command prompt:
pip install gensim
However, the following error appears when importing it:
Traceback (most recent call last):
File "C:/Users/PycharmProjects/untitled/file.py", line 3, in <module>
import gensim
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\gensim\__init__.py", line 5, in <module>
from gensim import parsing, corpora, matutils, interfaces, models, similarities, summarization, utils # noqa:F401
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\gensim\parsing\__init__.py", line 4, in <module>
from .preprocessing import (remove_stopwords, strip_punctuation, strip_punctuation2, # noqa:F401
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\gensim\parsing\preprocessing.py", line 42, in <module>
from gensim import utils
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\gensim\utils.py", line 40, in <module>
import scipy.sparse
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\scipy\__init__.py", line 156, in <module>
from . import fft
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\scipy\fft\__init__.py", line 76, in <module>
from ._basic import (
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\scipy\fft\_basic.py", line 1, in <module>
from scipy._lib.uarray import generate_multimethod, Dispatchable
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\scipy\_lib\uarray.py", line 27, in <module>
from ._uarray import *
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\scipy\_lib\_uarray\__init__.py", line 114, in <module>
from ._backend import *
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\scipy\_lib\_uarray\_backend.py", line 1, in <module>
from typing import (
ImportError: cannot import name 'Type'
I have also previously successfully installed the "typing" library":
pip install typing
What should I do?
It is because Python 3.5 has its own version typing, and it is incompatible with the installed version of gensim. Upgrade to python3.6 could solve the problem.

python sklearn import failed on libquadmath.so.0 in 3.5.1

Getting import Error while importing sklearn , the only Error code what it says is libquadmath.so.0 which i'm unale to see on the pkg path but same module works fine in 3.6.1.
>>> import sklearn
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/python3/lib/python3.5/site-packages/sklearn/__init__.py", line 57, in <module>
from .base import clone
File "/python3/lib/python3.5/site-packages/sklearn/base.py", line 11, in <module>
from .utils.fixes import signature
File "/python3/lib/python3.5/site-packages/sklearn/utils/__init__.py", line 11, in <module>
from .validation import (as_float_array,
File "/python3/lib/python3.5/site-packages/sklearn/utils/validation.py", line 16, in <module>
from ..utils.fixes import signature
File "/python3/lib/python3.5/site-packages/sklearn/utils/fixes.py", line 324, in <module>
from scipy.sparse.linalg import lsqr as sparse_lsqr
File "/python3/lib/python3.5/site-packages/scipy-0.18.0rc2-py3.5-linux-x86_64.egg/scipy/sparse/linalg/__init__.py", line 112, in <module>
from .isolve import *
File "/python3/lib/python3.5/site-packages/scipy-0.18.0rc2-py3.5-linux-x86_64.egg/scipy/sparse/linalg/isolve/__init__.py", line 6, in <module>
from .iterative import *
File "/python3/lib/python3.5/site-packages/scipy-0.18.0rc2-py3.5-linux-x86_64.egg/scipy/sparse/linalg/isolve/iterative.py", line 7, in <module>
from . import _iterative
ImportError: libquadmath.so.0: cannot open shared object file: No such file or directory

SVM import failed after installing scikit-neuralnetwork

I just installed Python's scikit-neuralnetwork using the procedure mentioned, that is;
pip install scikit-neuralnetwork
Now I can not import SVM. This line;
from sklearn import svm
gives this error;
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "//anaconda/lib/python2.7/site-packages/sklearn/svm/__init__.py", line 13, in <module>
from .classes import SVC, NuSVC, SVR, NuSVR, OneClassSVM, LinearSVC, \
File "//anaconda/lib/python2.7/site-packages/sklearn/svm/classes.py", line 4, in <module>
from .base import _fit_liblinear, BaseSVC, BaseLibSVM
File "//anaconda/lib/python2.7/site-packages/sklearn/svm/base.py", line 12, in <module>
from ..multiclass import _ovr_decision_function
File "//anaconda/lib/python2.7/site-packages/sklearn/multiclass.py", line 44, in <module>
from .metrics.pairwise import euclidean_distances
File "//anaconda/lib/python2.7/site-packages/sklearn/metrics/__init__.py", line 33, in <module>
from . import cluster
File "//anaconda/lib/python2.7/site-packages/sklearn/metrics/cluster/__init__.py", line 21, in <module>
from .bicluster import consensus_score
File "//anaconda/lib/python2.7/site-packages/sklearn/metrics/cluster/bicluster/__init__.py", line 1, in <module>
from .bicluster_metrics import consensus_score
File "//anaconda/lib/python2.7/site-packages/sklearn/metrics/cluster/bicluster/bicluster_metrics.py", line 6, in <module>
from sklearn.utils.validation import check_arrays
ImportError: cannot import name check_arrays
May I know what went wrong? I'll try using different environments next time, if that helps. Is there any way to fix this?
I am using Python 2.7 and sklearn 0.17.
open sklearn.utils.validation and delete "import check_arrays", or use other package for example anaconda3. i check now - no problems. Or install anaconda3.5 and copy check_arrays to anaconda2.7 sklearn.utils.validation.

What module is missing when I try to import skimage? Python 3.5

When I run the line from skimage import io I get the following:
Traceback (most recent call last):
File "C:\Users\Dilshad\Desktop\project_7-8-2015\8_bands\Program_camera.py", line 16, in <module>
from Functions_8bands import *
File "C:\Users\Dilshad\Desktop\project_7-8-2015\8_bands\Functions_8bands.py", line 5, in <module>
from skimage import io
File "C:\Users\Dilshad\AppData\Local\Programs\Python\Python35\lib\site-packages\skimage\io\__init__.py", line 11, in <module>
from ._io import *
File "C:\Users\Dilshad\AppData\Local\Programs\Python\Python35\lib\site-packages\skimage\io\_io.py", line 8, in <module>
from ..color import rgb2grey
File "C:\Users\Dilshad\AppData\Local\Programs\Python\Python35\lib\site-packages\skimage\color\__init__.py", line 1, in <module>
from .colorconv import (convert_colorspace,
File "C:\Users\Dilshad\AppData\Local\Programs\Python\Python35\lib\site-packages\skimage\color\colorconv.py", line 58, in <module>
from scipy import linalg
File "C:\Users\Dilshad\AppData\Local\Programs\Python\Python35\lib\site-packages\scipy\linalg\__init__.py", line 172, in <module>
from .misc import *
File "C:\Users\Dilshad\AppData\Local\Programs\Python\Python35\lib\site-packages\scipy\linalg\misc.py", line 5, in <module>
from .blas import get_blas_funcs
File "C:\Users\Dilshad\AppData\Local\Programs\Python\Python35\lib\site-packages\scipy\linalg\blas.py", line 155, in <module>
from scipy.linalg import _fblas
ImportError: DLL load failed: The specified module could not be found.
I've searched through the site-package file and I see that io exists so I'm not really sure whats's missing.
Not sure why it worked but installing numpy +mkl instead of numpy vanilla from the unofficial binary site on UCI got around this for me.

Error using the scikit-learn cluster package

I want to use the scikit-learn package on mac terminal. However, I encounter error executing the example program. The link to the example program. http://scikit-learn.org/stable/auto_examples/cluster/plot_dbscan.html#example-cluster-plot-dbscan-py
Traceback (most recent call last):
File "plot_dbscan.py", line 14, in <module>
from sklearn.cluster import DBSCAN
File "/Library/Python/2.7/site-packages/sklearn/cluster/__init__.py", line 6, in <module>
from .spectral import spectral_clustering, SpectralClustering
File "/Library/Python/2.7/site-packages/sklearn/cluster/spectral.py", line 13, in <module>
from ..utils import check_random_state, as_float_array
File "/Library/Python/2.7/site-packages/sklearn/utils/__init__.py", line 10, in <module>
from .murmurhash import murmurhash3_32
File "numpy.pxd", line 155, in init sklearn.utils.murmurhash (sklearn/utils/murmurhash.c:5029)
ValueError: numpy.dtype has the wrong size, try recompiling

Categories

Resources