How do I get my scikit-learn library to work on windows using pip package installer? - python

I am using the windows command prompt to install the scikit learn library using the command pip install -U scikit-learn. However, whenever I try to import it into my program I get an error stating that there is no module named 'sklearn'. Also, whenever I download the library using pip, for some reason, my pip package installer seems to break and pip is no longer recognized as a command on my cmd. I have numerous other modules which work perfectly fine so I don't see a reason as to why I can't get this specific library to work. I am still quite new to this kind of thing, so maybe I am missing something.
Traceback (most recent call last):
File "<pyshell#0>", line 1, in
import sklearn
File "C:\Users\Ryan\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn_init_.py", line 82, in
from .base import clone
File "C:\Users\Ryan\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\base.py", line 17, in
from .utils import IS_32BIT
File "C:\Users\Ryan\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\utils_init.py", line 20, in
from scipy.sparse import issparse
File "C:\Users\Ryan\AppData\Local\Programs\Python\Python39\lib\site-packages\scipy\sparse_init_.py", line 227, in
from .base import *
File "C:\Users\Ryan\AppData\Local\Programs\Python\Python39\lib\site-packages\scipy\sparse\base.py", line 4, in
from .sputils import (isdense, isscalarlike, isintlike,
File "C:\Users\Ryan\AppData\Local\Programs\Python\Python39\lib\site-packages\scipy\sparse\sputils.py", line 8, in
from scipy._lib._util import prod
ModuleNotFoundError: No module named 'scipy._lib._util'

Try to upgrade pip to newest version by python -m pip install --upgrade pip considering you are still using Windows. And then try to download sciKitLearn by pip install sklearn
This is how I had solved my problem but keep note that it was about a year ago
If all this doesn't work, try VirtualEnv.

Related

Pandas importing error " ImportError: cannot import name 'DtypeArg' from 'pandas._typing' "

When I try to import pandas, it throws an error. I cannot import pandas. I re-install pandas but it keeps ont throwing the same error.
I tried running it in a local prompt and in a jupyter notebook. I think it may conflict with the pip version so I removed the package from pip. Currently I just have the conda version but still same error. What can I do?
Traceback (most recent call last):
File "havatahmin.py", line 1, in <module>
import pandas as pd
File "C:\Anaconda\envs\ED\lib\site-packages\pandas\__init__.py", line 144, in <module>
from pandas.io.api import (
File "C:\Anaconda\envs\ED\lib\site-packages\pandas\io\api.py", line 8, in <module>
from pandas.io.excel import ExcelFile, ExcelWriter, read_excel
File "C:\Anaconda\envs\ED\lib\site-packages\pandas\io\excel\__init__.py", line 1, in <module>
from pandas.io.excel._base import ExcelFile, ExcelWriter, read_excel
File "C:\Anaconda\envs\ED\lib\site-packages\pandas\io\excel\_base.py", line 33, in <module>
from pandas.io.parsers import TextParser
File "C:\Anaconda\envs\ED\lib\site-packages\pandas\io\parsers\__init__.py", line 1, in <module>
from pandas.io.parsers.readers import (
File "C:\Anaconda\envs\ED\lib\site-packages\pandas\io\parsers\readers.py", line 17, in <module>
from pandas._typing import (
ImportError: cannot import name 'DtypeArg' from 'pandas._typing' (C:\Anaconda\envs\ED\lib\site-packages\pandas\_typing.py)
I confirm, it is a reproducible bug in pandas==1.3.1.
A workaround is to downgrade it to some earlier version, e.g. pip install pandas==1.3.0.
The woarkaround can be tested in build 20210717 of our python (3.8) CUDA-enabled containers:
docker run -d --rm --name ml-gpu-py38-cuda112-cust -p 8888:8888 -v /home/mir:/home/jovyan mirekphd/ml-gpu-py38-cuda112-cust:20210717 && docker logs -f ml-gpu-py38-cuda112-cust
Has it been already reported to pandas devs on Github?
Update: The issue still persists, so I've provided a reproducible example to Pandas devs in #42506.
This error can occur for multiple reasons.
pip install pandas --ignore-installed will break pandas between 1.3.0 and 1.3.1 because it does not remove old files from site-packages, thus the import error. If this is the case, you can re-install pandas without this flag.
pip install --force-reinstall pandas
Mixing conda and pip may also break pandas, as discussed here. For that matter, if you use conda, try to stick with it then install missing packages with pip. More guidelines on how to use pip in a Conda environment.

Pip Import Error No module named logging

Whenever I am running any command using pip, I am getting the following error. I have tried uninstalling python,pip and reinstalling them back again. I also used
sudo apt-get autoremove
and then updated and upgraded
sudo apt-get update
sudo apt-get upgrade
And once again installed python and pip. I am still getting the same error whenever I run any command using pip.
Traceback (most recent call last):
File "/usr/bin/pip", line 9, in <module>
from pip import main
File "/home/shashank/.local/lib/python2.7/site-packages/pip/__init__.py", line 28, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "/home/shashank/.local/lib/python2.7/site-packages/pip/vcs/mercurial.py", line 9, in <module>
from pip.download import path_to_url
File "/home/shashank/.local/lib/python2.7/site-packages/pip/download.py", line 34, in <module>
from pip.utils.logging import indent_log
ImportError: No module named logging
Can anybody suggest a solution?
Edit
I have read the question which is used to flag my question as a duplicate.
I am not using a virtual environment and I have already tried the answer given over there. Moreover I am encountering a problem when I run pip in my terminal
The output of the command
locate logging
/etc/java-9-openjdk/logging.properties
/home/shashank/.local/share/Trash/files/logging.py
/home/shashank/.local/share/Trash/files/logging.pyc
/home/shashank/.local/share/Trash/info/logging.py.trashinfo
/home/shashank/.local/share/Trash/info/logging.pyc.trashinfo
/lib/lsb/init-functions.d/50-ubuntu-logging
/usr/lib/jvm/java-9-openjdk-amd64/jmods/java.logging.jmod
/usr/lib/jvm/java-9-openjdk-amd64/lib/logging.properties
/usr/lib/pm-utils/sleep.d/00logging
/usr/lib/python2.7/logging
/usr/lib/python2.7/dist-packages/pip/utils/logging.py
/usr/lib/python2.7/dist-packages/pip/utils/logging.pyc
/usr/lib/python2.7/logging/__init__.py
/usr/lib/python2.7/logging/__init__.pyc
/usr/lib/python2.7/logging/config.py
/usr/lib/python2.7/logging/config.pyc
/usr/lib/python2.7/logging/handlers.py
/usr/lib/python2.7/logging/handlers.pyc
/usr/lib/python3/dist-packages/UnityTweakTool/config/logging.py
/usr/lib/python3/dist packages/UnityTweakTool/config/__pycache__/logging.cpython-35.pyc
/usr/lib/python3/dist-packages/plainbox/impl/logging.py
/usr/lib/python3/dist-packages/plainbox/impl/__pycache__/logging.cpython-35.pyc
/usr/lib/python3.5/logging
/usr/lib/python3.5/logging/__init__.py
/usr/lib/python3.5/logging/__pycache__
/usr/lib/python3.5/logging/config.py
/usr/lib/python3.5/logging/handlers.py
/usr/lib/python3.5/logging/__pycache__/__init__.cpython-35.pyc
/usr/lib/python3.5/logging/__pycache__/config.cpython-35.pyc
/usr/lib/python3.5/logging/__pycache__/handlers.cpython-35.pyc
/usr/share/icons/hicolor/16x16/categories/applications-microblogging-panel.png
/usr/share/icons/ubuntu-mono-dark/categories/22/applications-microblogging-panel.svg
/usr/share/icons/ubuntu-mono-dark/categories/24/applications-microblogging-panel.svg
/usr/share/icons/ubuntu-mono-light/categories/22/applications-microblogging-panel.svg
/usr/share/icons/ubuntu-mono-light/categories/24/applications-microblogging-panel.svg
/usr/src/linux-headers-4.4.0-59-generic/include/config/fusion/logging.h
/usr/src/linux-headers-4.4.0-59-generic/include/config/scsi/logging.h
/usr/src/linux-headers-4.4.0-59-generic/include/config/sfc/mcdi/logging.h
/usr/src/linux-headers-4.4.0-62-generic/include/config/fusion/logging.h
/usr/src/linux-headers-4.4.0-62-generic/include/config/scsi/logging.h
/usr/src/linux-headers-4.4.0-62-generic/include/config/sfc/mcdi/logging.h
It's obvious from your traceback that you have a version of pip installed in your home directory, at /home/shashank/.local/lib/python2.7/site-packages/pip/. Delete that. If you aren't certain what else is contained there, better delete all /home/shashank/.local/lib/python2.7. After you delete it, it will use the system's default pip that you installed with apt.

ImportError: Failed to import msrest.authentication

I have Python 2.7.9 with azure-2.0.0rc4 and msrest-0.4.0. My code failed to import from msrest.authentication. I checked the two files from azure and msrest packages, and could not find any issues.
Appreciate any advice and direction.
John
Traceback (most recent call last):
File "getCredential.py", line 1, in <module>
from azure.common.credentials import ServicePrincipalCredentials
File "/usr/local/lib/python2.7/site-packages/azure/common/credentials.py", line 25, in <module>
raise ImportError("You need to install 'msrest' to use this feature")
ImportError: You need to install 'msrest' to use this feature
This seems to be a bug with the pip install --pre azure.
Running this command afterwards installs the necessary packages:
pip install msrestazure
I found the issue. When I sudo pip install, read permission was not set for the others group. Once I fixed that, the issue went away.

Error importing sklearn (scikit learn package) in python [duplicate]

I'm trying to call a function from the cluster module, like so:
import sklearn
db = sklearn.cluster.DBSCAN()
and I get the following error:
AttributeError: 'module' object has no attribute 'cluster'
Tab-completing in IPython, I seem to have access to the base, clone, externals, re, setup_module, sys, and warning modules. Nothing else, though others (including cluster) are in the sklearn directory.
Following pbu's advice below and using
from sklearn import cluster
I get:
Traceback (most recent call last):
File "test.py", line 2, in <module>
from sklearn import cluster
File "C:\Python34\lib\site-packages\sklearn\cluster\__init__.py", line 6, in <module>
from .spectral import spectral_clustering, SpectralClustering
File "C:\Python34\lib\site-packages\sklearn\cluster\spectral.py", line 13, in <module>
from ..utils import check_random_state, as_float_array
File "C:\Python34\lib\site-packages\sklearn\utils\__init__.py", line 16, in <module>
from .class_weight import compute_class_weight, compute_sample_weight
File "C:\Python34\lib\site-packages\sklearn\utils\class_weight.py", line 7, in <module>
from ..utils.fixes import in1d
File "C:\Python34\lib\site-packages\sklearn\utils\fixes.py", line 318, in <module>
from scipy.sparse.linalg import lsqr as sparse_lsqr
File "C:\Python34\lib\site-packages\scipy\sparse\linalg\__init__.py", line 109, in <module>
from .isolve import *
File "C:\Python34\lib\site-packages\scipy\sparse\linalg\isolve\__init__.py", line 6, in <module>
from .iterative import *
File "C:\Python34\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.
I'm using Python 3.4 on Windows, scikit-learn 0.16.1.
You probably don't use Numpy+MKL, but only Numpy.
I had the same problem and reinstalling Numpy with MKL
pip install --upgrade --force-reinstall "numpy‑1.16.3+mkl‑cp37‑cp37m‑win32.whl"
fixed it.
Note: update the file to the latest version, possibly 64bit - see the list of available Windows binaries
Problem was with scipy/numpy install. I'd been using the (normally excellent!) unofficial installers from http://www.lfd.uci.edu/~gohlke/pythonlibs/. Uninstall/re-install from there made no difference, but installing with the official installers (linked from http://www.scipy.org/install.html) did the trick.
I am using anaconda got the same error as the OP, when loading Orange, or PlotNine.
I can't recall when this start to happen.
Tracing the dependency of Anaconda3\Lib\site-packages\scipy\special\_ufuncs.cp36-win32.pyd, libifcoremd.dll and libmmd.dll are missing in DependencyWalk. Searching them in anaconda root directry, they are located in both ICC_RT and one version of MKL package.
Adding Anaconda3\pkgs\mkl-2017.0.3-0\Library\bin to PATH, seems to fix SciPy and NumPy related DLL load failure, the above package starts to work again.
I still don't know how to fix this properly. Apparently the downside is that the MKL package could be updated and versions may change so does the path. In this aspect Its equally inconvenient as adding a non-managed package.
Reinstalling ICC_RT fixed the issue for me, libmmd.dll and the related dlls are automatically copied into anaconda3/library/bin afterwards, which is automatically added into PATH by activate command. All previous numpy/scipy related cant load DLL errors are gone now.
From the error log, it shows that scipy module is the most recent module fails to import
File "C:\Python34\lib\site-packages\sklearn\utils\fixes.py", line 318, in <module>
from scipy.sparse.linalg import lsqr as sparse_lsqr
File "C:\Python34\lib\site-packages\scipy\sparse\linalg\__init__.py", line 109, in <module>
from .isolve import *
File "C:\Python34\lib\site-packages\scipy\sparse\linalg\isolve\__init__.py", line 6, in <module>
from .iterative import *
File "C:\Python34\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.
I have the same error that show the same log, the problem'd gone when I uninstall/install scipy:
pip uninstall scipy
pip install scipy
Place this line on top of the python file
from sklearn import cluster
That should do it :))
For me what fixed it were these commands:
pip uninstall sklearn
pip uninstall scikit-learn
pip uninstall scipy
pip install scipy
pip install scikit-learnhere
I had the same issue and solved it by installing/updating the mkl package:
conda install mkl
or
pip install mkl
Just for full information, this also downgraded the following packages:
The following packages will be UPDATED:
mkl: 2017.0.4-h6d528fc_0 defaults --> 2018.0.3-1 defaults
The following packages will be DOWNGRADED:
numpy: 1.11.3-py34_0 defaults --> 1.10.1-py34_0 defaults
pandas: 0.19.2-np111py34_1 defaults --> 0.18.1-np110py34_0 defaults
scikit-learn: 0.18.1-np111py34_1 defaults --> 0.17-np110py34_1 defaults
scipy: 0.19.1-np111py34_0 defaults --> 0.16.0-np110py34_0 defaults
I struggled trying to figure this one out; tried to download and install the (unofficial) Numpy+MKL library from the website (risky/tedious?).
Ultimately found success by:
Login to command prompt using admin rights; how to here: https://superuser.com/questions/968214/open-cmd-as-admin-with-windowsr-shortcut
Uninstall existing/tangled version of Scipy & Numpy
pip uninstall scipy
pip uninstall numpy
Fresh install Scipy & Numpy
pip install scipy
pip install numpy
Run Jupyter notebook; it worked for me.
The message ImportError: DLL load failed: The specified module could not be found
informs that there is failure to identify and source the required DLL(s) to use the scikit-learn library; a fresh install of scipy/numpy probably enables a better routing of DLL connections called from Jupyter notebook code(s).
download microsoft visual c++ distribution
link : https://www.microsoft.com/en-in/download/details.aspx?id=53840
vc_redist.x64.exe
install and run this .exe file in your computer.. the DLL import module error will not appear after this
now it will work fine enjoy :)

Numpy and OpenCV

I'm tired to import cv and numpy and get errors. I started importing cv and I got this error:
ImportError: numpy.core.multiarray failed to import
Traceback (most recent call last):
File "", line 1, in <module>
File "/usr/lib/pymodules/python2.7/cv.py", line 1, in <module>
from cv2.cv import *
ImportError: numpy.core.multiarray failed to import
So I installed numpy on Ubuntu using:
apt-get install python-numpy
So when I import numpy I get:
Traceback (most recent call last):
File "", line 1, in <module>
File "numpy/init.py", line 127, in <module>
raise ImportError(msg)
ImportError: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python intepreter from there.
I really need help. I'm using Python 2.7.3 on Ubuntu.
There is nothing wrong with installing common dependencies using your operating system's package manager, remember using pip means your synaptic updates won't update your Python libraries and pip won't leverage the dependencies already taken care of by aptitude. For python packages with C extensions like numpy and opencv its probably better to use apt-get.
In Ubuntu you can install both dependencies with
sudo apt-get install python-numpy python-opencv
The actual Python error you are getting indicates what is wrong, namely that you are executing from within the numpy source directory, or have a file named numpy.py in your current directory which is confusing things at import time. Try change into an empty directory, start Python import your libraries:
import numpy
import cv
Hope that helps.
It's better that use some package management tool such like pip to install numpy.
For example,
pip install numpy

Categories