1. 程式人生 > >python常見錯誤(持續更新)

python常見錯誤(持續更新)

1.matplotlib畫圖報錯AttributeError: ‘module’ object has no attribute ‘popall’
解決方法如下:
原版本1.2.0升級成2.0.2

rpm -e python-matplotlib-1.2.0-15.el7.x86_64
pip install matplotlib==2.0.2

2.解碼錯誤UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xe5 in position 108: ordinal not in range
解決方法:程式碼快裡設定字符集為utf8

import sys
reload(sys)
sys.setdefaultencoding('utf8')

3.用tensorflow或者caffe做機器學習時
RuntimeError: module compiled against API version 0xa but this version of numpy is 0x9
基本上都是numpy版本的問題
解決方法

pip list|grep numpy
pip install numpy==1.3.1(視具體情況)

4.python編譯碰到錯誤
configure: error: no acceptable C compiler found in $PATH
原因缺少編譯器
安裝gcc即可

yum install -y gcc*