Error in checking sklearn version - python

I am onto practising ML using python and visited through this link.
I installed all of the packages mentioned in the link namely, scipy, numpy, matplotlib, pandas, sklearn and implemented the following code to check their respective versions and proper installation,
# scikit-learn
import sklearn
print('sklearn: {}'.format(sklearn.__version__))
but got the following error:
Traceback (most recent call last):
File "VersionCheck.py", line 19, in <module>
import sklearn
File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\__init__.py", line 134, in <module>
from .base import clone
File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\base.py", line 13, in <module>
from .utils.fixes import signature
File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\utils\__init__.py", line 11, in <module>
from .validation import (as_float_array,
File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\utils\validation.py", line 18, in <module>
from ..utils.fixes import signature
File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\utils\fixes.py", line 144, in <module>
from scipy.sparse.linalg import lsqr as sparse_lsqr # noqa
File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\scipy\sparse\linalg\__init__.py", line 114, in <module>
from .isolve import *
File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\scipy\sparse\linalg\isolve\__init__.py", line 6, in <module>
from .iterative import *
File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\scipy\sparse\linalg\isolve\iterative.py", line 7, in <module>
from . import _iterative
ImportError: DLL load failed: The specified module could not be found.

To see a version of sklearn installed:
from sklearn import __version__
print(__version__)

Related

Error importing scikit-image library in Python

I install Python 3.10.6 [MSC v.1932 32 bit (Intel)] on win32. Also install scikit-image in version'0.18.3'.
When I type "from skimage import io", the following error is displayed:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
from skimage import io
File "C:\Users\admin\AppData\Local\Programs\Python\Python310-32\lib\site-packages\skimage\io\__init__.py", line 11, in <module>
from ._io import *
File "C:\Users\admin\AppData\Local\Programs\Python\Python310-32\lib\site-packages\skimage\io\_io.py", line 4, in <module>
from ..color.colorconv import rgb2gray, rgba2rgb
File "C:\Users\admin\AppData\Local\Programs\Python\Python310-32\lib\site-packages\skimage\color\__init__.py", line 1, in <module>
from .colorconv import (convert_colorspace,
File "C:\Users\admin\AppData\Local\Programs\Python\Python310-32\lib\site-packages\skimage\color\colorconv.py", line 56, in <module>
from scipy import linalg
File "C:\Users\admin\AppData\Local\Programs\Python\Python310-32\lib\site-packages\scipy\linalg\__init__.py", line 198, in <module>
from ._misc import *
File "C:\Users\admin\AppData\Local\Programs\Python\Python310-32\lib\site-packages\scipy\linalg\_misc.py", line 3, in <module>
from .blas import get_blas_funcs
File "C:\Users\admin\AppData\Local\Programs\Python\Python310-32\lib\site-packages\scipy\linalg\blas.py", line 213, in <module>
from scipy.linalg import _fblas
ImportError: DLL load failed while importing _fblas: The specified module could not be found.
What is the problem? Please guide me. Thanks.

Is there a way to run Python code in Pydev?

I'm new to Jython and PyDev. I need to run my Python code in Eclipse.
The Python code works in Spyder/Jupyter Notebooks. When I run the programm as Jython Run/Python Run, an error pops up.
How can I solve this problem?
console: Failed to install '': java.nio.charset.UnsupportedCharsetException: cp0.
C:\Users\Hai Mi\Anaconda3\Lib\site-packages\numpy\__init__.py:140: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
from . import _distributor_init
Traceback (most recent call last):
File "C:\Users\Hai Mi\workspace\Camunda\learning_classify.py", line 7, in <module>
import nltk
File "C:\Users\Hai Mi\Anaconda3\Lib\site-packages\nltk\__init__.py", line 129, in <module>
from nltk.collocations import *
File "C:\Users\Hai Mi\Anaconda3\Lib\site-packages\nltk\collocations.py", line 40, in <module>
from nltk.metrics import ContingencyMeasures, BigramAssocMeasures, TrigramAssocMeasures, QuadgramAssocMeasures
File "C:\Users\Hai Mi\Anaconda3\Lib\site-packages\nltk\metrics\__init__.py", line 16, in <module>
from nltk.metrics.scores import (
File "C:\Users\Hai Mi\Anaconda3\Lib\site-packages\nltk\metrics\scores.py", line 18, in <module>
from scipy.stats.stats import betai
File "C:\Users\Hai Mi\Anaconda3\Lib\site-packages\nltk\metrics\scores.py", line 18, in <module>
from scipy.stats.stats import betai
File "C:\Users\Hai Mi\Anaconda3\Lib\site-packages\scipy\__init__.py", line 62, in <module>
from numpy import show_config as show_numpy_config
File "C:\Users\Hai Mi\Anaconda3\Lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import core
File "C:\Users\Hai Mi\Anaconda3\Lib\site-packages\numpy\core\__init__.py", line 24, in <module>
from . import multiarray
File "C:\Users\Hai Mi\Anaconda3\Lib\site-packages\numpy\core\__init__.py", line 24, in <module>
from . import multiarray
File "C:\Users\Hai Mi\Anaconda3\Lib\site-packages\numpy\core\multiarray.py", line 14, in <module>
from . import overrides
File "C:\Users\Hai Mi\Anaconda3\Lib\site-packages\numpy\core\overrides.py", line 166
SyntaxError: unqualified exec is not allowed in function 'decorator' because it contains free variables
Looks like a similar issue was discussed here
How do I fix UnsupportedCharsetException in Eclipse Kepler/Luna with Jython/PyDev?
and adding
-Dpython.console.encoding=UTF-8
to the Run Configurations -> VM arguments could be a solution.

cannot import pyLDAvis - ModuleNotFoundError: No module named '_contextvars'

I am trying to import pyLDAvis but it gives the error ModuleNotFoundError: No module named '_contextvars' although I installed both pyLDAvis and contextvars. The error is as follows
Traceback (most recent call last):
File "C:/Users/ebru/Documents/Arda Docs/Mydocs/ITLS/Research/Tüpraş/Python Codes/Tupras_NLPv04.py", line 249, in <module>
import pyLDAvis
File "C:\Users\ebru\PycharmProjects\Tuprasv01\venv\lib\site-packages\pyLDAvis\__init__.py", line 44, in <module>
from ._display import *
File "C:\Users\ebru\PycharmProjects\Tuprasv01\venv\lib\site-packages\pyLDAvis\_display.py", line 7, in <module>
import jinja2
File "C:\Users\ebru\PycharmProjects\Tuprasv01\venv\lib\site-packages\jinja2\__init__.py", line 82, in <module>
_patch_async()
File "C:\Users\ebru\PycharmProjects\Tuprasv01\venv\lib\site-packages\jinja2\__init__.py", line 78, in _patch_async
from jinja2.asyncsupport import patch_all
File "C:\Users\ebru\PycharmProjects\Tuprasv01\venv\lib\site-packages\jinja2\asyncsupport.py", line 13, in <module>
import asyncio
File "C:\Users\ebru\AppData\Local\Programs\Python\Python37-32\lib\asyncio\__init__.py", line 8, in <module>
from .base_events import *
File "C:\Users\ebru\AppData\Local\Programs\Python\Python37-32\lib\asyncio\base_events.py", line 39, in <module>
from . import events
File "C:\Users\ebru\AppData\Local\Programs\Python\Python37-32\lib\asyncio\events.py", line 14, in <module>
import contextvars
File "C:\Users\ebru\AppData\Local\Programs\Python\Python37-32\lib\contextvars.py", line 1, in <module>
from _contextvars import Context, ContextVar, Token, copy_context
ModuleNotFoundError: No module named '_contextvars'
I tried to delete the underscore in contextvars.py but it did not work.
Plotting tools
import pyLDAvis
import pyLDAvis.sklearn
According to https://github.com/axnsan12/drf-yasg/issues/362#issuecomment-494360308, this problem might result from virtualenv not upgrading to the Python version you have installed.
Also, 3.7.4 has been released & includes changes related to Context Variables. Maybe upgrading to that helps?

Setting up scikit-learn - numpy errors on import

I'm trying to set up scikit-learn, but after installing numpy and scikit-learn (using pip) that's what I get when trying to imort sklearn:
import sklearn
RuntimeError: module compiled against API version 8 but this version of numpy is 7
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/sklearn/__init__.py", line 32, in <module>
from .base import clone
File "/usr/local/lib/python2.7/site-packages/sklearn/base.py", line 10, in <module>
from scipy import sparse
File "/Library/Python/2.7/site-packages/scipy-0.13.0.dev_c31f167_20130304-py2.7-macosx-10.8-intel.egg/scipy/sparse/__init__.py", line 182, in <module>
from .csr import *
File "/Library/Python/2.7/site-packages/scipy-0.13.0.dev_c31f167_20130304-py2.7-macosx-10.8-intel.egg/scipy/sparse/csr.py", line 15, in <module>
from .sparsetools import csr_tocsc, csr_tobsr, csr_count_blocks, \
File "/Library/Python/2.7/site-packages/scipy-0.13.0.dev_c31f167_20130304-py2.7-macosx-10.8-intel.egg/scipy/sparse/sparsetools/__init__.py", line 5, in <module>
from .csr import *
File "/Library/Python/2.7/site-packages/scipy-0.13.0.dev_c31f167_20130304-py2.7-macosx-10.8-intel.egg/scipy/sparse/sparsetools/csr.py", line 26, in <module>
_csr = swig_import_helper()
File "/Library/Python/2.7/site-packages/scipy-0.13.0.dev_c31f167_20130304-py2.7-macosx-10.8-intel.egg/scipy/sparse/sparsetools/csr.py", line 22, in swig_import_helper
_mod = imp.load_module('_csr', fp, pathname, description)
ImportError: numpy.core.multiarray failed to import
Tried to reinstall things without success
Looking at this issue on github, it sounds like it might require a specific version of numpy - they used 1.7.0b2.

Numpy: ImportError: cannot import name TestCase

I installed numpy from
sudo apt-get install numpy
Then in python2.7 on importing numpy with
import numpy
I get this error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/numpy/__init__.py", line 137, in <module>
import add_newdocs
File "/usr/local/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 9, in <module>
from numpy.lib import add_newdoc
File "/usr/local/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 4, in <module>
from type_check import *
File "/usr/local/lib/python2.7/dist-packages/numpy/lib/type_check.py", line 8, in <module>
import numpy.core.numeric as _nx
File "/usr/local/lib/python2.7/dist-packages/numpy/core/__init__.py", line 45, in <module>
from numpy.testing import Tester
File "/usr/local/lib/python2.7/dist-packages/numpy/testing/__init__.py", line 8, in <module>
from unittest import TestCase
ImportError: cannot import name TestCase
I then removed Numpy and Scipy. Then again installed from the github repo. But I still get the same error. Please help.
Thank You.
I suspect that you have a local file called unittest.py that is getting imported instead of the standard module.

Categories