» pip install missingpy
For anyone who encounters the issue of not being able to import missingpy, try installing the following packages with specific versions:
scikit-learn==1.1.2
scipy==1.9.1
missingpy==0.2.0
You don't really need to install sklearn, which is a deprecated version of scikit-learn. Also, remember to add the following code when importing missingpy:
import sklearn.neighbors._base # this is from `scikit-learn` instead of `sklearn`
import sys
sys.modules['sklearn.neighbors.base'] = sklearn.neighbors._base
from missingpy import MissForest # remember to put this after sys.modules
It seems to be correct, try updating your packages,
Code Output:

I think I see your issue.
According to the requirements.txt for missingpy, the version of scikit-learn you need is 0.20.1. Unfortunately, that version won't easily install on any version of python later than version 3.8. If you happen to be on 3.8 or earlier, all you have to do is go to your command line and run
pip uninstall scikit-learn
pip install scikit-learn==0.20.1
Once you have the right version, you won't need to do any craziness with renaming modules. You can just do this:
import sklearn.neighbors.base
import missingpy
However, downgrading your environment to an earlier version of python just to use a single library isn't always a great idea. Look into other options for your specific use case and see if you can find a more modern solution than missingpy.
In summary, if you really need to use missingpy, your procedure is:
- Rollback your python version to 3.8 (if needed)
- Rollback your
scikit-learnversion to 0.20.1 - Import your modules (in order)
To unistall: py -m pip install -U scikit-learn
py -m pip install scikit-learn. Was released Released: Feb 16, 2024
py -m pip show scikit-learn