痛哭,越往后学放在debug上的时间越多(虽然好多都不会,但我最大的优点可能就是坚持了吧,哭)
接下来,把我这节课遇到的部分问题呈上来(哭):
运行mnist_app.py时,
一、TypeError: ‘str’ object cannot be interpreted as an integer
原因:
testNum = input("Input the number of test pictures:") # 输入要识别几张图片
而在python 3.x中,input读取的类型是str(字符串),在这里要读取输入的图片张数,就需要转换成int类型。
解决方法:
testNum = int(input("Input the number of test pictures:")) #输入要识别几张图片
二、NameError: name ‘raw_input’ is not defined
原因:
testPic = raw_input("the path of test picture:") #给出识别图片的路径和名称
raw_input()是python2.x版本的输入函数,在python3.x版本中已被input()代替。
解决方法:
testPic = input("the path of test picture:") #给出识别图片的路径和名称
三、PyCharm安装配置PIL发生错误
解决方法:
一般安装配置包时,在PyCharm中我一般使用“File→Settings→Project→project Interpreter→点击界面右边的+,搜索并install包”,如下图:
但是下载PIL时,出现了报错。经过查找,发现换做安装Pillow-PIL就OK啦。