最开始是使用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
发现能够运行。