【问题标题】:ERROR after I changed to python 2.7from python3 ( anaconda3 and eclipse )我从 python3 ( anaconda3 和 eclipse ) 更改为 python 2.7 后出现错误
【发布时间】:2017-10-31 15:56:38
【问题描述】:

使用以下命令:

conda create -n py27 python=2.7

为了将python3改为python 2.7

然后我运行代码

from sklearn.feature_extraction import DictVectorizer
import csv
from sklearn import tree
from sklearn import preprocessing
from sklearn.externals.six import StringIO

# Read in the csv file and put features into list of dict and list of      class label
allElectronicsData = open(r'D:\mycodes\test01\AllElectronics.csv', 'rb')
reader = csv.reader(allElectronicsData)
headers = reader.next()

错误:

Finding files... done.
Importing test modules ... Traceback (most recent call last):
File "D:\huanjing\eclipse-java-neon-R-win32-    x86_64\eclipse\plugins\org.python.pydev_5.7.0.201704111357\pysrc\_pydev_runfi    les\pydev_runfiles.py", line 468, in __get_module_from_str
mod = __import__(modname)
File "D:\mycodes\test01\tree.py", line 1, in <module>
from sklearn.feature_extraction import DictVectorizer
ImportError: No module named sklearn.feature_extraction
ERROR: Module: tree could not be imported (file:         D:/mycodes/test01/tree.py).
done.

Ran 0 tests in 0.000s

好的

貌似我改了python版本后,需要重新安装conda中的所有python包?

【问题讨论】:

    标签: python eclipse python-2.7


    【解决方案1】:

    是的,Python 2.7 和 Python 3 将使用不同的包。在您的 conda 环境中运行以下命令:

    $ conda install numpy
    $ conda install scipy
    $ conda install scikit-learn
    

    【讨论】:

    • 没问题,我知道您是 SO 新手。如果您认为此答案解决了问题,请单击绿色复选标记将其标记为“已接受”。这有助于将注意力集中在仍然没有答案的旧 SO 问题上。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-21
    • 2012-11-13
    • 1970-01-01
    • 2020-01-24
    • 2013-08-11
    相关资源
    最近更新 更多