ModuleNotFoundError: No module named 'sklearn'

前端 未结 10 1310
天涯浪人
天涯浪人 2020-12-29 17:37

I want to import sklearn but there is no module apparently:

ModuleNotFoundError: No module named \'sklearn\'

I am using Anaconda and

相关标签:
10条回答
  • 2020-12-29 18:20

    install these ==>> pip install -U scikit-learn scipy matplotlib if still getting the same error then , make sure that your imoprted statment should be correct. i made the mistike while writing ensemble so ,(check spelling) its should be >>> from sklearn.ensemble import RandomForestClassifier

    0 讨论(0)
  • 2020-12-29 18:28

    You can just use pip for installing packages, even when you are using anaconda:

    pip install -U scikit-learn scipy matplotlib
    

    This should work for installing the package.

    And for Python 3.x just use pip3:

    pip3 install -U scikit-learn scipy matplotlib
    
    0 讨论(0)
  • 2020-12-29 18:30

    If you are using Ubuntu 18.04 or higher with python3.xxx then try this command

    $ sudo apt install python3-sklearn 
    

    then try your command. hope it will work

    0 讨论(0)
  • 2020-12-29 18:30

    I had the same issue as the author, and ran into the issue with and without Anaconda and regardless of Python version. Everyone's environment is different, but after resolving it for myself I think that in some cases it may be due to having multiple version of Python installed. Each installed Python version has its own \Lib\site-packages\ folder which can contain a unique set of modules for that Python version, and where the IDE looks into folder path that doesn't have scikit-learn in it.

    One way to try solve the issue: you might clear your system of all other Python versions and their cached/temp files/system variables, and then only have one version of Python installed anywhere. Then install the dependencies Numpy and Scipy, and finally Scikit-learn.

    More detailed steps:

    1. Uninstall all Python versions and their launchers (e.g. from Control Panel in Windows) except the one version you want to keep. Delete any old Python version folders in the Python directory --uninstalling doesn't remove all files.
    2. Remove other Python versions from your OS' Environment Variables (both under the system and user variables sections)
    3. Clear temporary files. For example, for Windows, delete all AppData Temp cache files (in C:\Users\YourUserName\AppData\Local\Temp). In addition, you could also do a Windows disk cleanup for other temporary files, and then reboot.
    4. If your IDE supports it, create a new virtual environment in Settings, then set your only installed Python version as the interpreter.
    5. In your IDE, install the dependencies Scipy and Numpy from the module list first, then install Scikit-Learn.

    As some others have suggested, the key is making sure your environment is set up correctly where everything points to the correct library folder on your computer where the Sklearn package is located. There are a few ways this can be resolved. My approach was more drastic, but it turns out that I had a very messy Python setup on my system so I had to start fresh.

    0 讨论(0)
提交回复
热议问题