最開始是使用matplotlib這個包,而後在pycharm中失敗,而後在終端中pip install matplotlib,發現,安裝了之後,pycharm依然找不到包。python
代碼以下:macos
import numpy as np import tensorflow as tf import matplotlib.pyplot as plt num_points = 1000 vectors_set = [] for i in range(num_points): x1 = np.random.normal(0.0, 0.55) y1 = x1 * 0.1 + 0.3 + np.random.normal(0.0, 0.03) vectors_set.append([x1, y1]) x_data = [v[0] for v in vectors_set] y_data = [v[1] for v in vectors_set] plt.scatter(x_data,y_data,c='r') plt.show()
/anaconda3/envs/tensorflow/bin/python3.6 /Users/tanchao/Documents/pythonwork/tensorflow/test.py,正確vim
使用命令:bash
which python
返回結果:app
說明終端默認的python解釋器和pycharm中的不一致。dom
在終端中輸入spa
open ~/.bash_profile
寫入:3d
export PATH=${PATH}:/Library/Frameworks/Python.framework/Versions/3.6/bin
重命名python(不知道該步驟是否有必要)code
alias python="/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6"
而後終端中輸入:orm
source ~/.bash_profile
在終端中輸入:
which python
查看是否成功。
發現此時終端的python解釋器和pycharm的解釋器一致。
發現還有錯。
相似於這樣的錯誤
from matplotlib.backends import _macosx RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are Working with Matplotlib in a virtual enviroment see 'Working with Matplotlib in Virtual environments' in the Matplotlib FAQ
在終端中輸入
vim ~/.matplotlib/matplotlibrc
在文件中輸入:
backend: TkAgg
發現能夠運行。