简体   繁体   中英

Python: Can't fix "ModuleNotFoundError: No module named 'sklearn' "

I already installed sklearn through pip install scikit-learn but I still get this message when I try to run it

当我尝试运行它时出现此消息

I already tried a bunch of stuff to fix it. But nothing seems to work.

Can anyone help me?

As @TasosPapastylianou said, your current pip defaults to pip3 and installs scikit-learn to python3 libraries.

You need to check which version of python is your iris.py using. (It should be available in the top lines of that file). Most probably it is using only python . Something like this:

#!/usr/bin/env python

You can check which version the python command is using by doing:

python -V

Most probably it will default to python2 and not python3 .

There are multiple ways to solve this:

  1. Try python3 iris.py to execute the script.

  2. Change the shebang in the top line of the file to:

    #!/usr/bin/env python3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM