ImportError: No module named sklearn (Python)

2020-08-09 11:39发布

I wanna use scikit-learn. I have typed

pip install -U scikit-learn
pip3 install sklearn

to install it; but when i type

$ Python
>>> import sklearn

it returns

ImportError: No module named sklearn

I followed other tutorials, but it doesn't work. Furthermore, my enviroment returns this warning:

If you have installed scikit-learn from source, please do not forget to build the package before using it: run python setup.py install or make in the source directory.

What is the true code to type in the terminal? I tried to type python setup.py installin the terminal but it doesn't work

5条回答
【Aperson】
2楼-- · 2020-08-09 11:56

Not only for this package but also for almost cases, please try using python3 -m pip install sklearn if pip install sklearn does not work.

查看更多
冷血范
3楼-- · 2020-08-09 11:58

I think you havent install sklearn, try this on your python terminal:

pip install sklearn

and proceed with your code

查看更多
倾城 Initia
4楼-- · 2020-08-09 12:03

Try:

pip3 install scikit-learn
查看更多
相关推荐>>
5楼-- · 2020-08-09 12:10

you dont have the package scikit-learn installed, try this if you are in a terminal linux :

sudo pip install scikit-learn

if you want to install the package within your code use

import os 
os.system('sudo pip install scikit-learn')
查看更多
孤傲高冷的网名
6楼-- · 2020-08-09 12:21

Make sure that pip and python are the same version. For example if you run pip for python 2.7, it will install the package only in 2.7, and if your python command point to for example python 3.3 interpreter, it will not have that package

查看更多
登录 后发表回答