小记:
昨天买的《TensorFlow实战》到货,急着安装tensorflow,但是一天都没安装成功。虽然网上的安装教程很多,找起来也费尽,今天又花了大半天终于弄好了,所以写了个小文章记录一下。
配置
1.OS:Win10,64位
2.Anaconda3-4.2.0-Windows-x86_64(其中Python版本是3.5.2)
3.Pycharm
安装Anaconda:
因为Tensorflow只支持Python3.5x版本的,不支持最新版本3.6的,所以默认安装Anaconda的话就无法顺利安装Tensorflow,所以需要安装老点的版本,这里给出链接:这里,这里选择的是Anaconda3-4.2.0-Windows-x86_64,因为这里的python版本是3.5.2。
安装Tensorflow
1、在 开始->Anaconda3->Anaconda Prompt输入下列代码
2、>conda
3、>pip install tensorflow
安装成功
问题
在Pycharm输入下面的代码
import tensorflow as tf
hello = tf.constant('hello,tf')
sess = tf.Session()
print(sess.run(hello))
虽然能够得到正确的结果,却也有异常,如下
E c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] OpKernel ('op: "BestSplits" device_type: "CPU"') for unknown op: BestSplits
E c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] OpKernel ('op: "CountExtremelyRandomStats" device_type: "CPU"') for unknown op: CountExtremelyRandomStats
E c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] OpKernel ('op: "FinishedNodes" device_type: "CPU"') for unknown op: FinishedNodes
E c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] OpKernel ('op: "GrowTree" device_type: "CPU"') for unknown op: GrowTree
E c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] OpKernel ('op: "ReinterpretStringToFloat" device_type: "CPU"') for unknown op: ReinterpretStringToFloat
E c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] OpKernel ('op: "SampleInputs" device_type: "CPU"') for unknown op: SampleInputs
E c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] OpKernel ('op: "ScatterAddNdim" device_type: "CPU"') for unknown op: ScatterAddNdim
E c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] OpKernel ('op: "TopNInsert" device_type: "CPU"') for unknown op: TopNInsert
E c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] OpKernel ('op: "TopNRemove" device_type: "CPU"') for unknown op: TopNRemove
E c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] OpKernel ('op: "TreePredictions" device_type: "CPU"') for unknown op: TreePredictions
E c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] OpKernel ('op: "UpdateFertileSlots" device_type: "CPU"') for unknown op: UpdateFertileSlots
目前还不是很清楚具体的原因,但是也有个解决办法,就是在 import tensorflow
之前设置提示信息的等级:
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' # 只显示 Error
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' # 只显示 warning 和 Error
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '1' # 这是默认的显示等级,显示所有信息
就可以解决这个问题。即
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
import tensorflow as tf
hello = tf.constant('hello,tf')
sess = tf.Session()
print(sess.run(hello))
此时输出的结果是正常的:
b'hello,tf'