前几天我已经安装了scikitslearn,我尝试执行的代码如下。
import skflow
from sklearn import datasets, metrics
iris = datasets.load_iris()
classifier = skflow.TensorFlowLinearClassifier(n_classes=3)
classifier.fit(iris.data, iris.target)
score = metrics.accuracy_score(classifier.predict(iris.data), iris.target)
print("Accuracy: %f" % score)
上面的代码是我在Githubgist页面上找到的。结果是
ImportError Traceback (most recent call last)
<ipython-input-1-16b804f4d3b1> in <module>()
----> 1 import skflow
2 from sklearn import datasets, metrics
3
4 iris = datasets.load_iris()
5 classifier = skflow.TensorFlowLinearClassifier(n_classes=3)
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/skflow/__init__.py in <module>()
16 import pkg_resources as pkg_rs
17 import numpy as np
---> 18 import tensorflow as tf
19
20 from skflow.io import *
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow/__init__.py in <module>()
21 from __future__ import print_function
22
---> 23 from tensorflow.python import *
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow/python/__init__.py in <module>()
43 _default_dlopen_flags = sys.getdlopenflags()
44 sys.setdlopenflags(_default_dlopen_flags | ctypes.RTLD_GLOBAL)
---> 45 from tensorflow.python import pywrap_tensorflow
46 sys.setdlopenflags(_default_dlopen_flags)
47
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py in <module>()
26 fp.close()
27 return _mod
---> 28 _pywrap_tensorflow = swig_import_helper()
29 del swig_import_helper
30 else:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py in swig_import_helper()
22 if fp is not None:
23 try:
---> 24 _mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
25 finally:
26 fp.close()
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so, 10): no suitable image found. Did find:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so: mach-o, but wrong architecture
我最近才开始编码,所以我根本无法处理这个问题。。这里的"错误架构"是什么意思??希望有人回答这个问题。
看起来您安装了错误版本的tensorflow。在这种情况下,错误的体系结构可能意味着您在OS X上安装了linux版本的TF。
我建议卸载tensorflow和skflow,然后运行以下命令(对于带有Python2.7的OS X):
sudo easy_install --upgrade six
sudo pip install --upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.8.0rc0-py2-none-any.whl
Skflow现在是TensorFlow的一部分,因此您可以通过导入import tensorflow.contrib.learn as skflow
而不是import skflow
来使用。