Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python code get error in eclipse while it runs fine in terminal

I tried to run sklearn example, when I try to run it via terminal everything works fine but when I copy and paste this code in eclipse and try to run it I get this error:

Traceback (most recent call last):   File "/Users/ABC/Documents/Eclipse/workspace/project/src/sklearn/plot_ROC.py", line 9, in <module>
    from sklearn import svm, datasets ImportError: cannot import name svm

I check that both eclipse and system using the same version of python (at least I think so)

In terminal when I typed "which python" the result is "//anaconda/bin/python"
And in eclipse I set the same for Python interpreter as you can see in below picture.
enter image description here

So can anyone guide me what is the problem?

like image 673
Am1rr3zA Avatar asked Apr 17 '26 03:04

Am1rr3zA


1 Answers

you may compare Python path under Eclipse and terminal by

import sys
print ( sys.path )

the order of entries does matter. My guess is that the fact that your Python file is in a folder called sklearn ( i.e .../project/src/sklearn) is messing the import statement.

requested edit: as it turned out, the problem was that the Python script was in a folder called sklearn and Python would look into that folder to import svm.

like image 145
behzad.nouri Avatar answered Apr 18 '26 15:04

behzad.nouri