1

I am writing my first machine learning program. I am totally new i am writing the python code in pycharm but i am getting error as below. i can't even find any tutorial for beginners maybe most people don't know it

ModuleNotFoundError: No module named 'scipy'

from sklearn import  tree
features = [[140,1],[130,1],[150,0],[170,0]]
labels = [0,0,1,1]
clf = tree.DecisionTreeClassifier()
clf = clf.fit(features,labels)
print(clf.predict([[150, 0]]))

Traceback (most recent call last): File "C:/Users/LENOVO/PycharmProjects/MyPython/MyPyton.py", line 1, in from sklearn import tree File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn__init__.py", line 134, in from .base import clone File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\base.py", line 10, in from scipy import sparse ModuleNotFoundError: No module named 'scipy'

sarvesh chavan
  • 33
  • 1
  • 2
  • 7

5 Answers5

3

Here's another option: Presumably you downloaded Python from python.org (i.e. you searched the web for "download Python" and clicked on the first link, which is fair enough). Instead, I suggest downloading and using the Anaconda Python distribution, which comes with a scipy (and many other useful packages) precompiled for Windows.

Edit: A month after posting this answer, scipy 1.0 was released and one of the features was pre-built binary wheels for Windows. In plain language, this means you can now run pip install scipy on Windows and it will just work. However, there are still plenty of Python packages that need building but do not have pre-built wheels for Windows, so overall it is still sensible to use Anaconda (or similar) to install Python and packages.

Arthur Tacca
  • 6,565
  • 1
  • 27
  • 42
2

The module you're importing depends on another module. Do pip install scipy. If you don't have pip, you can read about it here: https://pypi.python.org/pypi/pip

2

Installing scipy is probably most easily done from within PyCharm. The full instructions are in the PyCharm documentation, but in summary:

  1. Go to setting (open from the file menu) and go to the Project Interpreter page.
  2. Click the green plus symbol on the right
  3. Use the dialogue box that appears to search for "scipy"
  4. Click on "Install Package"
Arthur Tacca
  • 6,565
  • 1
  • 27
  • 42
  • error numpy.distutils.system_info.NotFoundError: no lapack/blas resources found sol Try to run this command from the system terminal. Make sure that you use the correct version of 'pip' installed for your Python interpreter located at 'C:\Users\LENOVO\AppData\Local\Programs\Python\Python36\python.exe'. – sarvesh chavan Sep 14 '17 at 16:14
1

On your terminal, try to run python -m pip list and check if scipy is installed. If isnt, use python -m pip install scipy, to install module.

Abe
  • 1,074
  • 9
  • 29
  • which terminal? how should i open the terminal ? – sarvesh chavan Sep 14 '17 at 16:03
  • if you're using Windows, open the CMD. Linux, open your terminal, console of something like this. If Mac, same on linux. – Abe Sep 14 '17 at 16:05
  • do i have to navigate in python directory ? – sarvesh chavan Sep 14 '17 at 16:06
  • no, if `python` was installed properly, it already is located at your `PATH` variable, so, u can run this command in any location – Abe Sep 14 '17 at 16:07
  • C:\Windows\system32>python -m pip list 'python' is not recognized as an internal or external command, operable program or batch file. – sarvesh chavan Sep 14 '17 at 16:09
  • try to see [this tutorial](https://stackoverflow.com/questions/6318156/adding-python-path-on-windows-7) and after that, run the command. – Abe Sep 14 '17 at 16:10
  • I did exactly according to that tutorial like this https://i.imgur.com/wUTS9Dg.png But in my cmd i am getting error https://i.imgur.com/rjuiJeB.png – sarvesh chavan Sep 14 '17 at 16:30
0

Are you trying to call any scipy functions? The code you gave doesn't seem to have any-and you have not imported the api. It looks like you're using sci-kit learn, in which case, depending on which distribution platform you used-you may need to pip install it-which is really easy!

user7351362
  • 171
  • 1
  • 9