1. 程式人生 > >RuntimeError: Python is not installed as a framework. Mac下使用Matplotlib報錯

RuntimeError: Python is not installed as a framework. Mac下使用Matplotlib報錯

使用為python環境導致的 使用虛擬環境以別匯入matplotlib中的內容會報錯 需要先匯入再設定一下

import matplotlib
matplotlib.use('TkAgg')
from matplotlib import pyplot as plt

修改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 "
[email protected]
"
function frameworkpython {
    if [[ ! -z "$VIRTUAL_ENV" ]]; then
        PYTHONHOME=$VIRTUAL_ENV /usr/local/bin/python "[email protected]"
    else
        /usr/local/bin/python "[email protected]"
    fi
}