標籤:

anaconda安裝tensorflow,在import tensorflow時報錯,要怎麼解決?

(C:UsersyyqAnaconda2) C:Usersyyq&>python

Python 2.7.13 |Continuum Analytics, Inc.| (default, Dec 19 2016, 13:29:36) [MSC v.1500 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license" for more information.

Anaconda is brought to you by Continuum Analytics.

Please check out: http://continuum.io/thanks and :: Anaconda Cloud

&>&>&> import tensorflow

Traceback (most recent call last):

File "&", line 1, in &

File "C:UsersyyqAnaconda2libsite-packages ensorflow\__init__.py", line 24, in &

from tensorflow.python import *

File "C:UsersyyqAnaconda2libsite-packages ensorflowpython\__init__.py", line 60, in &

raise ImportError(msg)

ImportError: Traceback (most recent call last):

File "C:UsersyyqAnaconda2libsite-packages ensorflowpython\__init__.py", line 54, in &

from tensorflow.python import pywrap_tensorflow

File "C:UsersyyqAnaconda2libsite-packages ensorflowpythonpywrap_tensorflow.py", line 28, in &

_pywrap_tensorflow = swig_import_helper()

File "C:UsersyyqAnaconda2libsite-packages ensorflowpythonpywrap_tensorflow.py", line 20, in swig_import_helper

import _pywrap_tensorflow

ImportError: No module named _pywrap_tensorflow

Error importing tensorflow. Unless you are using bazel,

you should not try to import tensorflow from its source directory;

please exit the tensorflow source tree, and relaunch your python interpreter

from there.

&>&>&>


有回答建議創建虛擬環境,其實有點繞圈子。

問題關鍵是tensorflow要求3.5.2版本的python,而現在安裝最新的anaconda默認是3.6的python。

解決方法如下

管理員模式打開cmd

輸入conda install python=3.5.2

然後再正常pip安裝tensorflow即可

此時spyder和ipython也是python 3.5.2


問題解決了,原因是我沒有將tensorflow的依賴包安裝完全,我分享一下我的整個安裝過程 吧,我使用anaconda安裝的

1、創建一個python3.5的虛擬環境:conda create -n tensorflow python=3.5

2、activate tensorflow激活虛擬環境

3、安裝tensorflow的依賴包:

wheel

six (&>=1.10.0)

protobuf (&>=3.1.0)

numpy (&>=1.11.0)

mock (&>=2.0.0)

(用pip install whell命令直接安裝,其中,numpy要安裝numpy+mkl,在Python Extension Packages for Windows網站可以找到各種python依賴包,下載對應的numpy+mkl版本:numpy-1.11.3+mkl-cp35-cp35m-win_amd64.whl,用pip install C:*********
umpy-1.11.3+mkl-cp35-cp35m-win_amd64.whl)

4、查看依賴包安裝情況

conda list

#

mock 2.0.0 &

pbr 1.10.0 &

pip 9.0.1 py35_1

protobuf 3.2.0 &

python 3.5.2 0

setuptools 27.2.0 py35_1

six 1.10.0 &

vs2015_runtime 14.0.25123 0

wheel 0.29.0 py35_0

5、pip install tensorflow直接可以安裝tensorflow。


樓主問題解決沒我也遇到同樣的問題


No module,沒有安裝模塊,安裝下。

不要在tensorflow目錄下運行,否則無法訪問該目錄,跳到上一層目錄。

安裝Protobuf的時候遇到過這種提示,重新安裝下好了。


推薦閱讀:

求通俗講解下tensorflow的embedding_lookup介面的意思?
用Tensorflow自動化構建海洋生物系統,利用上萬的圖片訓練,找到瀕臨物種「海牛」是什麼原理?
請問batch_normalization做了normalization後為什麼要變回來?
當tensorflow模型超過單張顯卡顯存的時候,應該怎麼拆分到多個GPU上運行?
tensorflow是如何求導的?

TAG:TensorFlow |