15

I installed "imbalanced-learn" (version 0.3.1) on ANACONDA Navigator. When I ran an example from the imbalanced-learn website using Jupyter (Python 3):

from imblearn.datasets import make_imbalance
from imblearn.under_sampling import NearMiss
from imblearn.pipeline import make_pipeline
from imblearn.metrics import classification_report_imbalanced

I got an message regarding "ModuleNotFoundError".

ModuleNotFoundError: No module named 'imblearn'

How could I resolve this?

blackraven
  • 5,284
  • 7
  • 19
  • 45
TTZ
  • 823
  • 2
  • 9
  • 19

14 Answers14

19

Problems importing imblearn python package on ipython notebook

Found the answer here. This worked for me

conda install -c glemaitre imbalanced-learn
TTZ
  • 823
  • 2
  • 9
  • 19
  • 2
    Here's a more official one now: `conda install -c conda-forge imbalanced-learn` – msarafzadeh Jan 01 '20 at 18:22
  • 1
    this didn't help me to import imblearn package, what did help me was !pip install imblearn, this is a verified answer and now I am curious to know if this answer helped anybody or not. Please comment if anybody was actually able to solve their proble by this approach. Thank you! – sareek Jan 13 '22 at 19:32
  • hi @sareek i'm a conda user, so this worked for me :-) – blackraven Aug 23 '22 at 23:34
6

This worked for me:

!pip install imblearn

Then, I was able to import SMOTE package.

from imblearn.over_sampling import SMOTE
Daniel Puiu
  • 962
  • 6
  • 21
  • 29
Pratibha
  • 61
  • 1
  • 1
2

imbalanced-learn is currently available on the PyPi’s reporitories and you can install it via pip:

pip install -U imbalanced-learn

The package is release also in Anaconda Cloud platform:

conda install -c conda-forge imbalanced-learn

enter image description here

enter image description here

blackraven
  • 5,284
  • 7
  • 19
  • 45
TomHardy
  • 117
  • 1
  • 4
1

Just in case someone encounters this problem on Google Cloud Jupyter notebook instances, using pip3 to install imblearn made it work for me, after failing with pip command:

pip3 install imblearn

or directly in the notebook:

!pip3 install imblearn

You should see imblearn (0.0) and imbalanced-learn (4.3) in your pip list.

NB! Make sure to reload your notebooks (File -> Close and Shutdown), otherwise it might fail to import the library after install.

1
conda install -c conda-forge imbalanced-learn 

It just worries down the problem

barbsan
  • 3,418
  • 11
  • 21
  • 28
1

One of the below four commands should work. Only the 3rd worked for me.

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

conda install -c conda-forge/label/cf202003 imbalanced-learn

1

The below code is the most updated one:

conda update -n base -c defaults conda

from imblearn.over_sampling import SMOTE

Beezet
  • 31
  • 3
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 02 '22 at 12:41
0

I have faced the same problem and I installed imblearn first by typing this command:

!pip install imblearn  

in jupyter notebook and then it is fine

mrun
  • 744
  • 6
  • 19
  • 24
Hatem
  • 9
  • 1
0

Just check if you antivirus or firewall is blocking the download process. I too had the same issue. This happens when you try to install through Anaconda. During the installation process there occurs a permission error. This is probably due to antivirus blocking the download process.

0

Open Anaconda Prompt and type in

pip install imbalanced-learn --user
0

I am working on Jupyter notebook, this work for me:

pip install imblearn
Nafees Ahmed
  • 93
  • 12
0

I used in this code in my Jupyter Notebook and it works fine.

! pip install imbalanced-learn
Nisrin Dhoondia
  • 145
  • 1
  • 10
0

Use this:

!pip3 install imblearn --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --user

This will override SSL certificate requirement and complete the installation.

If after this you still get the error, restart the kernel and run just the import code, not this install command again. That will import imblearn successfully.

Rakesh
  • 1
  • 2
0

I needed to upgrade pip first:

pip3 install --upgrade pip

then, and only then, was I able to install imbalanced-learn:

pip3 install imbalanced-learn
ChrisDanger
  • 1,071
  • 11
  • 10