使用為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
}