简体   繁体   English

MAC上的PyCharm-ModuleNotFoundError:没有名为“ sklearn”的模块

[英]PyCharm on MAC - ModuleNotFoundError: No module named 'sklearn'

I'm using PyCharm and learning the basics of Machine Learning through a Mooc. 我正在使用PyCharm并通过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' 当我尝试import sklearn as pd时(找不到作为“代码”的方法),我得到ModuleNotFoundError: No module named 'sklearn'

I've had the same issue with pandas and numpy previously and was able to solve it by adding 我以前在pandas和numpy中遇到过同样的问题,并且能够通过添加来解决

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. 并尝试在终端(我在Mac上)上进行一些操作,例如pip install numpyconda install numpy但这一次似乎没有任何效果。

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 :) 我怀疑问题是sklearn在我计算机上的其他地方,而不是Python程序正在搜索的地方,但不确定。.请告诉我是否可以提供帮助:)

It may be that Pycharm is using a different interpreter environment than you were using before. Pycharm使用的解释器环境可能与您之前使用的环境不同。 Best way to check is in Pycharm go to Pycharm on the menu, then preferences, then under 'Project' choose 'Project Interpreter'. 最好的检查方法是在Pycharm中转到菜单上的Pycharm,然后选择首选项,然后在“项目”下选择“项目解释器”。 At the top a dropdown will show you what environment Pycharm is using for this project. 顶部的下拉列表将显示Pycharm用于此项目的环境。 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. 奇怪的是,您选择import sklearn as pd因为这不是惯例。 The convention is to import pandas as pd . 惯例是import pandas as pd Technically it is not incorrect, the interpreter will accept it, but it is not the convention. 从技术上讲,它是不正确的,解释器将接受它,但这不是约定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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