使用为python环境导致的 使用虚拟环境以别导入matplotlib中的内容会报错 需要先导入再设置一下
import matplotlib
matplotlib.use('TkAgg')
from matplotlib import pyplot as plt
或是添加设置到文件中
vi ~/.matplotlib/matplotlibrc
backend: TkAgg
官方给出了设置虚拟环境的文档但是由于我使用的pipenv 没能生效 virtualenv使用matplotlib
修改python环境地址
#!/bin/bash
# what real Python executable to use
PYVER=2.7
PATHTOPYTHON=/usr/local/bin/
PYTHON=${PATHTOPYTHON}python${PYVER}
# find the root of the virtualenv, it should be the parent of the dir this script is in
ENV=`$PYTHON -c "import os; print(os.path.abspath(os.path.join(os.path.dirname(\"$0\"), '..')))"`
# now run Python with the virtualenv set as Python's HOME
export PYTHONHOME=$ENV
exec $PYTHON "$@"
function frameworkpython {
if [[ ! -z "$VIRTUAL_ENV" ]]; then
PYTHONHOME=$VIRTUAL_ENV /usr/local/bin/python "$@"
else
/usr/local/bin/python "$@"
fi
}