1. 程式人生 > >python 2.7匯入matplotlib報錯,亂碼問題

python 2.7匯入matplotlib報錯,亂碼問題

import matplotlib.pyplot as plt

報錯如下:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xcd in position 60: ordinal not in range(128)

解決:

方法一:

把專案的路徑改成全英文

方法二:有時候不可行,原因不知道

# coding=utf-8
import sys
reload(sys)
sys.setdefaultencoding('gbk')