Unable to import sklearn.mixture in CP3



Hello! I’m currently writing my own module that uses a 2-component Gaussian mixture model (sklearn.mixture.GaussianMixture) from scikit-learn 0.19.0 to cluster the intensity of objects into background and signal. I’ve managed to make it work in a standalone python script using exported data from another cpproj, but as soon as I place imports into my module.py, I get the following behavior:

If I include import sklearn, no error is thrown until sklearn.mixture.GaussianMixture is called during the module’s run() in Start Test Mode, at which point I get:

AttributeError: ‘module’ object has no attribute ‘mixture’

If I instead include import sklearn.mixture, a different error is thrown at startup:

ImportError: No module named mixture

I’m not sure how to utilize sklearn in my module. Any help would be appreciated. Thanks!

EDIT: The import is successful in the dev build of cellprofiler (3.1.4).


I realize this is something you solved yourself but at the moment I’m trying to help out with dependency management and the associated expectations.

The binary releases of CellProfiler 3.0.0 for Windows and macOS both ship with scikit-learn 0.19.0. sklearn.mixture.GaussianMixture was added in version 0.18.0 of scikit-learn.

Do you remember or have access to how you had CellProfiler installed before you solved the problem?


Sorry for the late reply. I just had Cellprofiler 3.0.0 (the stable build) binary installed; upon initialization with the plugins directory pointing to where I had the module with sklearn.mixture, the terminal displayed the above errors. Please let me know if you’re able to replicate it (my machine is running Windows 10).