Am1rr3zA
Am1rr3zA

Reputation: 7421

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?

Upvotes: 3

Views: 404

Answers (1)

behzad.nouri
behzad.nouri

Reputation: 77951

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.

Upvotes: 1

Related Questions