简体   繁体   中英

PyCharm on MAC - ModuleNotFoundError: No module named 'sklearn'

I'm using PyCharm and learning the basics of Machine Learning through a Mooc.

As always, things don't go as expected when you try things shown by the teacher by yourself and until now I was able to fix the issues by myself but I'm stuck since quite a while and that's why I created an account here :)

when I try import sklearn as pd (can't find how to do this as "code") I get ModuleNotFoundError: No module named 'sklearn'

I've had the same issue with pandas and numpy previously and was able to solve it by adding

import sys

sys.path.append("numpy_path/pandas_path")

and trying some things on the terminal (I'm on Mac) like pip install numpy or conda install numpy but this time nothing seems to work.

I suspect the issue to be that sklearn is somewhere else on my computer than where the Python program is searching but am not sure.. Let me know if you can help :)

It may be that Pycharm is using a different interpreter environment than you were using before. Best way to check is in Pycharm go to Pycharm on the menu, then preferences, then under 'Project' choose 'Project Interpreter'. At the top a dropdown will show you what environment Pycharm is using for this project. Underneath will be all the libraries you have installed in that environment. You can look down the list and check if the libraries you want are installed. If they aren't hit the + button underneath, search for the libraries, select and hit install.

Also a note. It's odd that you are choosing to import sklearn as pd as that is not the convention. The convention is to import pandas as pd . Technically it is not incorrect, the interpreter will accept it, but it is not the convention.

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