UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xbd in position 11: ordinal not in range(128)

Windows默认的编码方式是GBK

在使用python调用matlab相关的patplotlib.pyplot库进行画图操作时遇到“UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xbd in position 11: ordinal not in range(128)”错误

import matplotlib.pyplot as plt
1
解决方法一:

在Python程序最前面加上以下语句:

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


注:此方法针对Python 2.7无效

解决方法二:

在Python程序最前面加上以下语句:

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

注:Python 2.7 适用

原文:https://blog.csdn.net/lk3030/article/details/79964263 
 

猜你喜欢

转载自blog.csdn.net/tony2278/article/details/84142385