TensorFlow使用中遇到的错误(更新中)

1.python premade_estimator.py出错

错误描述

Traceback (most recent call last):

  File "premade_estimator.py", line 22, in <module>
    import iris_data
  File "/home/fboy/tensorflow_code/models/samples/core/get_started/iris_data.py", line 1, in <module>
    import pandas as pd
ImportError: No module named 'pandas'

原因是没有安装pandas,下面安装pandas

sudo pip install pandas   

安装成功以后还是报错,说没有pandas。后来在google一查才知道在python3下使用的pandas与panthon2下不一样,需要安装python3对应的pandas。

sudo apt-get install python3-pandas

这句是安装python3-pandas对应的pandas,安装后再跑TensorFlow的例程就可以了。


2. 实战TensorFlow第三章,计算图的使用

跑一个例程的时候出现如下的错误:

Traceback (most recent call last):

  File "3.1.2.py", line 7, in <module>
    v = tf.get_variable("v", initializer=tf.zeros_initializer(shape=[1]))
TypeError: __init__() got an unexpected keyword argument 'shape'

原因是书上的代码太旧了,现在已经更新了。更改如下:

v = tf.get_variable("v", shape=[1], initializer=tf.zeros_initializer)

还有一个警告:

WARNING:tensorflow:From/home/user/tensorflow/lib/python3.5/site-packages/tensorflow/python/util/tf_should_use.py:118: initialize_all_variables (from tensorflow.python.ops.variables) is deprecated and will be removed after 2017-03-02.
Instructions for updating:

Use `tf.global_variables_initializer` instead.

tf.initialize_all_variables().run() #更改成以下的代码

tf.global_variables_initializer()#这样警告就没有了


3.python问题:IndentationError:expected an indented block错误解决

有冒号的下一行往往要缩进。遇到这种情况一般是格式出错了,缩进。


4. SyntaxError: Missing parentheses in call to 'print'

原因:python2和python3不兼容。我电脑中装了python3,但是代码确实按照python2的格式来写的。

print result#

在python3中应改成:print (result)

如果输入字符串应该改成:print("hello")



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值