21

I tried running the following code:

from imblearn import under_sampling, over_sampling
from imblearn.over_sampling import SMOTE

sm = SMOTE(random_state=12, ratio = 1.0)
x_SMOTE, y_SMOTE = sm.fit_sample(X, y) 

which gives me the error message:

ModuleNotFoundError: No module named 'imblearn'

I have tried installing the imblearn module in multiple ways, they all seem to work (there are no errors given during the installation but when I run the above code, I get an error message).

I tried istalling imblearn using the following suggested in other stackoverflow questions:

pip install -U imbalanced-learn
pip install imblearn
!pip install imblearn
pip install -c glemaitre imbalanced-learn
pip install imblearn==0.0

None of these seem to help... Any ideas? Thank you!

Alexander L. Hayes
  • 3,892
  • 4
  • 13
  • 34
bernando_vialli
  • 947
  • 4
  • 12
  • 27
  • @piRSquared any ideas? – bernando_vialli May 16 '18 at 17:58
  • *None of these seem to help.* Did the commands work? If not what were the errors? How do you run the script? Do you have more than 1 python installed? Let's verify: what give `python --version` and `pip --version`? – phd May 16 '18 at 19:14
  • 1
    python -- version is Python 3.6.4. Pip -- version is pip 10.0.1 from c:\users\mkheifetz\......etc etc\pip (python 3.6) – bernando_vialli May 16 '18 at 19:20
  • The only error I got was the module not found error. I ran all python code in a Jupyter Notebook. The pip installs were all done on the command prompt – bernando_vialli May 16 '18 at 19:21
  • @bernando_vialli do you have any solution, I've also tried everything (including the answers to this SO question). When I'm trying the jupyter book inplace pip install, I'm getting ... already satisfied, but on the import I'm getting `No module named ...` – Kraego Mar 04 '22 at 13:09

13 Answers13

22

I installed the module named imblearn using anaconda command prompt.

conda install -c conda-forge imbalanced-learn

Then imported the packages

from imblearn import under_sampling, over_sampling
from imblearn.over_sampling import SMOTE

Again, I tried to install imblearn through pip, it works for me.

(base) C:\WINDOWS\system32>pip install -U imbalanced-learn
Requirement already up-to-date: imbalanced-learn in c:\users\ashok\anaconda3\lib\site-packages (0.4.3)
Requirement already satisfied, skipping upgrade: numpy>=1.8.2 in c:\users\ashok\anaconda3\lib\site-packages (from imbalanced-learn) (1.15.3)
Requirement already satisfied, skipping upgrade: scipy>=0.13.3 in c:\users\ashok\anaconda3\lib\site-packages (from imbalanced-learn) (0.19.1)
Requirement already satisfied, skipping upgrade: scikit-learn>=0.20 in c:\users\ashok\anaconda3\lib\site-packages (from imbalanced-learn) (0.20.0)
Ashok Kumar Jayaraman
  • 2,887
  • 2
  • 32
  • 40
9

On AWS SageMaker, follow the documentation:

!pip install imbalanced-learn

in a notebook cell.

5

This worked for me

  1. First install the package in your environment:
pip install -U imbalanced-learn
  1. Next:
conda install -c conda-forge imbalanced-learn
Mohnish
  • 1,010
  • 1
  • 12
  • 20
Ankita
  • 91
  • 1
  • 8
2

Open anaconda prompt and install below module:

conda install -c conda-forge imbalanced-learn
conda install -c conda-forge/label/gcc7 imbalanced-learn
conda install -c conda-forge/label/cf201901 imbalanced-learn
1

Those who have permission issue or failed to install it can follow this.

  • conda create --name dsc_new
  • conda activate dsc_new
  • conda install -c conda-forge imbalanced-learn
  • try on your notebook pip install imbalanced-learn --user
Ninja Master
  • 126
  • 3
1

I was dealing with the same problem. Updating packages, upgrading pip or python version did not resolve the problem for me.

The issue was that pip installed package to one folder, but my jupyter notebook imported packages from another folder. To get the path from where your packages are imported, you may use:

import site
site.getsitepackages() 

# /your/path/from/python

Then you may check in terminal where pip installs your packages :

pip show imblearn

If the paths do not coincide, you may manually set the path for pip in terminal:

pip config set global.target /your/path/from/python

And install your package again by

pip install imblearn
weirdan
  • 2,499
  • 23
  • 27
1

I have been fixed it by applying the following inside a Jupyter Notebook.

!pip install imbalanced-learn==0.6.0
!pip install scikit-learn==0.22.1
1

I had the same issue which was rectified by using:

   !pip install -U imbalanced-learn

Then this:

   conda install -c conda-forge imbalanced-learn

Updated my conda:

   conda update -n base -c conda-forge conda

Restarted the kernel.

Ebony
  • 11
  • 1
0

try this way:

from imblearn import under_sampling 
from imblearn import over_sampling
from imblearn.over_sampling import SMOTE

OR

import imblearn *
krock1516
  • 441
  • 10
  • 30
0

I've come across the same problem a few days ago - trying to use imblearn inside a Jupyter Notebook. This question led me to the solution:

conda install -c glemaitre imbalanced-learn

Notice, one of the commands you tried (pip install -c glemaitre imbalanced-learn) doesn't make sense: -c glemaitre is an argument for Anaconda python distributions, which tells conda (Anaconda's CLI) to download the module from a source different than the defaults (glemaitre's channel). Since that argument is conda-specific, it doen't apply to pip commands.

Julio Cezar Silva
  • 2,148
  • 1
  • 21
  • 30
0

Using python=3.6.10 and below worked for me.

0

If you are still experiencing error after installing imblearn either on Anaconda terminal while using Vscode. Try to restart Vscode for it to reflect.

Sonola Moyo
  • 11
  • 1
  • 3
0

It is working for me this way

pip install imblearn

And i import this way :

from imblearn.combine import SMOTETomek
biihu
  • 69
  • 6