1

I tried to install scikit-learn in OSGeo4W Shell.

I used the information provided by another question 1. Both ways as AlecZ suggested worked.

After installation I get this message: "Successfully installed scikit-learn-0.24.2"

Although when I open QGIS and then try to import sklearn I get this error: "ModuleNotFoundError: No module named 'sklearn.utils'"

How can I fix that and import the library?

2
  • which Operating System are you using?
    – Matt
    Commented Sep 7, 2021 at 16:59
  • Microsoft Windows 10
    – Annie S.
    Commented Sep 7, 2021 at 17:01

1 Answer 1

4

On Windows, you must activate the QGIS environment before using pip

For QGIS 3.20 and higher: Open OsGeo shell, then type:

o4w_env

python3 -m pip install scikit-learn -U --user

For QGIS 3.18 and lower: Open OsGeo shell, then type:

py3_env.bat

python3 -m pip install scikit-learn -U --user

3
  • I have QGIS 3.18 and I already did those steps but still, the same error pops up
    – Annie S.
    Commented Sep 7, 2021 at 17:05
  • can you please add the successful installation message to your question? It might give some clues about what went wrong. Namely, the path where the scikit package was installed.
    – Matt
    Commented Sep 7, 2021 at 17:14
  • 1
    I uninstalled 3.18 and install 3.20 and all worked well!
    – Annie S.
    Commented Sep 8, 2021 at 6:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.