cannot import sklearn even though it is installed successfully - python

I have installed sklearn through pip successfully using this command:
$pip install -U scikit-learn
But I cannot import it.
import sklearn
Result:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-b7c74cbf5af0> in <module>
----> 1 import sklearn
ModuleNotFoundError: No module named 'sklearn'
Please help

You might want to try installing scikit-learn: pip install scikit-learn

Try pip3 install sklearn.
This will install the libraries you need for python 3.

Related

Cannot import pycaret in google colab

I cant import pycaret in a google colab
Here are all the steps I had taken:
Change python version to 3.8
Installed pip
I then ran
!pip install pycaret
import pycaret
the install works, but then
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-27-fdea18e6876c> in <module>
1 get_ipython().system('pip install pycaret ')
----> 2 import pycaret
ModuleNotFoundError: No module named 'pycaret'
I must be doing something very wrong!
In troubleshooting I also pip installed numpy and pandas which both imported just fine
For importing use this, this is one is for classification:
from pycaret.classification import *
And for regression:
from pycaret.regression import *
For NLP:
from pycaret.nlp import *
!pip install pycaret
should work without any issues. I have used it multiple times on Google Colab. Alternately, you can use
pip install --pre pycaret

ModuleNotFoundError: No module named 'word2number' Error

While installed 'word2number' using command
from word2number import w2n
I am getting this error while using Google Colab:
ModuleNotFoundError: No module named 'word2number' Error
May I know how do I solve the error?
You probably need to run
!pip install word2number
to install the library to Google colab. import statements don't install libraries, they load libraries that are already installed (a lot of libraries come pre installed).
While trying to install word2number same error is coming
!pip install word2number
from word2number import w2n
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
/tmp/ipykernel_27/3199678630.py in <module>
1 get_ipython().system('pip install word2number')
----> 2 from word2number import w2n
ModuleNotFoundError: No module named 'word2number'

ImportError: cannot import name 'metrics' from 'skimage'

Here's the part that involves the use of skimage in the code:
from skimage import metrics
....
print(metrics.mean_squared_error(gray_frame, canny_img))
print(metrics.peak_signal_noise_ratio(gray_frame, canny_img))
Here's the error:
C:\Users\user\Desktop>python cannyopencv2.py
Traceback (most recent call last):
File "cannyopencv2.py", line 6, in <module>
from skimage import metrics
ImportError: cannot import name 'metrics' from 'skimage' (C:\ProgramData\Anaconda3\lib\site-packages\skimage\__init__.py)
Please help me get rid of it.
Try to install latest version of skimage because that version does not have that module in it so use below command to upgrade it!
pip install scikit-image -U
or
pip install scikit-image --upgrade
You need to install the package first in order to use it.
pip install scikit-image or pip3 install scikit-image
docs

ModuleNotFoundError: No module named 'mglearn'

This is a commmon question, but nothing worked for me so far.
I have seen this answer too Python 3 on Mac : ModuleNotFoundError: No module named 'mglearn'
!pip install mglearn
!pip install sklearn
!pip install -U scikit-learn
import mglearn
import sklearn
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-fe22f30497b9> in <module>
----> 1 import mglearn
2 import sklearn
ModuleNotFoundError: No module named 'mglearn'
I checked other questions but failed to solve it. I have macOS Catalina 10.15.7
import sys
!{sys.executable} -m pip install mglearn
Try using this. This assures that you are using the pip version associated with the environment.

xgboost on Sagemaker notebook import fails

I am trying to use XGBoost on Sagemaker notebook.
I am using conda_python3 kernel, and the following packages are installed:
py-xgboost-mutex
libxgboost
py-xgboost
py-xgboost-gpu
But once I am trying to import xgboost it fails on import:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-5-5943d1bfe3f1> in <module>()
----> 1 import xgboost as xgb
ModuleNotFoundError: No module named 'xgboost'
In Sagemaker notebooks use the below steps
a) If in Notebook
i) !type python3
ii) Say the above is /home/ec2-user/anaconda3/envs/python3/bin/python3 for you
iii) !/home/ec2-user/anaconda3/envs/python3/bin/python3 -m pip install xgboost
iv) import xgboost
b) If using Terminal
i) conda activate conda_python3
ii) pip install xgboost
Disclaimer : sometimes the installation would fail with gcc version ,in that case update pip version before running install

Categories