zpx1002 发表于 2019-11-17 10:41:56

No module named 'matplotlib'

请问 matplotlib 在Mac上怎么安装呀?我已经安装了anaconda,上网查了之后,在终端里输入sudo pip install --upgrade --ignore-installed matplotlib
结果显示不成功。求助各位,谢谢!

终端显示结果:
(base) MacdeMacBook-Air:~ mac$ sudo pip install --upgrade --ignore-installed matplotlib
Password:
WARNING: The directory '/Users/mac/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
WARNING: The directory '/Users/mac/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting matplotlib
Downloading https://files.pythonhosted.org/packages/c3/8b/af9e0984f5c0df06d3fab0bf396eb09cbf05f8452de4e9502b182f59c33b/matplotlib-3.1.1-cp37-cp37m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (14.4MB)
   |████████████████████████████████| 14.4MB 771kB/s
Collecting kiwisolver>=1.0.1 (from matplotlib)
Downloading https://files.pythonhosted.org/packages/df/93/8bc9b52a8846be2b9572aa0a7c881930939b06e4abe1162da6a0430b794f/kiwisolver-1.1.0-cp37-cp37m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (113kB)
   |████████████████████████████████| 122kB 11.9MB/s
Collecting cycler>=0.10 (from matplotlib)
Downloading https://files.pythonhosted.org/packages/f7/d2/e07d3ebb2bd7af696440ce7e754c59dd546ffe1bbe732c8ab68b9c834e61/cycler-0.10.0-py2.py3-none-any.whl
Collecting numpy>=1.11 (from matplotlib)
Downloading https://files.pythonhosted.org/packages/60/9a/a6b3168f2194fb468dcc4cf54c8344d1f514935006c3347ede198e968cb0/numpy-1.17.4-cp37-cp37m-macosx_10_9_x86_64.whl (15.1MB)
   |████████████████████████████████| 15.1MB 3.4MB/s
Collecting pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 (from matplotlib)
Downloading https://files.pythonhosted.org/packages/c0/0c/fc2e007d9a992d997f04a80125b0f183da7fb554f1de701bbb70a8e7d479/pyparsing-2.4.5-py2.py3-none-any.whl (67kB)
   |████████████████████████████████| 71kB 10.9MB/s
Collecting python-dateutil>=2.1 (from matplotlib)
Downloading https://files.pythonhosted.org/packages/d4/70/d60450c3dd48ef87586924207ae8907090de0b306af2bce5d134d78615cb/python_dateutil-2.8.1-py2.py3-none-any.whl (227kB)
   |████████████████████████████████| 235kB 9.5MB/s
Collecting setuptools (from kiwisolver>=1.0.1->matplotlib)
Downloading https://files.pythonhosted.org/packages/d9/de/554b6310ac87c5b921bc45634b07b11394fe63bc4cb5176f5240addf18ab/setuptools-41.6.0-py2.py3-none-any.whl (582kB)
   |████████████████████████████████| 583kB 13.5MB/s
Collecting six (from cycler>=0.10->matplotlib)
Downloading https://files.pythonhosted.org/packages/65/26/32b8464df2a97e6dd1b656ed26b2c194606c16fe163c695a992b36c11cdf/six-1.13.0-py2.py3-none-any.whl
ERROR: astroid 2.3.1 requires typed-ast<1.5,>=1.4.0; implementation_name == "cpython" and python_version < "3.8", which is not installed.
ERROR: astroid 2.3.1 has requirement six==1.12, but you'll have six 1.13.0 which is incompatible.      我安装的是3.8的python
Installing collected packages: setuptools, kiwisolver, six, cycler, numpy, pyparsing, python-dateutil, matplotlib
Successfully installed cycler-0.10.0 kiwisolver-1.1.0 matplotlib-3.1.1 numpy-1.17.4 pyparsing-2.4.5 python-dateutil-2.8.1 setuptools-41.6.0 six-1.13.0

我的代码:
import csv

from matplotlib import pyplot as plt
from datetime import datatime

filename = 'death_valley_2018_full.csv'
with open(filename) as f:
    reader = csv.reader(f)
    header_row = next(reader)

    dates.highs,lows =[],[],[]
    for row in reader:
      date=datetime.striptime(row,'%Y-%m-%d')
      dates.append(date)
      highs.append(row)
      lows.append(row)
    print(highs,lows)


fig = plt.figure()
plt.plot(dates,highs,c ='red')
plt.plot(dates,lows,c ='blue')

plt.title('daily temperatures,2018',fontsize=24)
plt.xlabel('date',fontsize=16)
plt.ylabel('temperature',fontsize=16)
plt.tick_params(axis='both',which='major',labelsize=16)

plt.show()


运行结果:
Traceback (most recent call last):
File "/Users/mac/Desktop/2.py", line 3, in <module>
    from matplotlib import pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'

zpx1002 发表于 2019-11-17 10:56:00

请问这样是成功了吗但运行代码还是不行
Successfully installed cycler-0.10.0 kiwisolver-1.1.0 matplotlib-3.1.1 numpy-1.17.4 pyparsing-2.4.5 python-dateutil-2.8.1 six-1.13.0
You are using pip version 18.1, however version 19.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

zpx1002 发表于 2019-11-17 11:39:36

电脑里已经安装了anaconda-navigator
哎。。还是不行啊

heidern0612 发表于 2019-11-17 19:25:40

zpx1002 发表于 2019-11-17 11:39
电脑里已经安装了anaconda-navigator
哎。。还是不行啊

提示告诉你让你升级Pip。

You should consider upgrading via the 'pip install --upgrade pip' command.

运行这个命令试试。

zpx1002 发表于 2019-11-17 19:39:33

heidern0612 发表于 2019-11-17 19:25
提示告诉你让你升级Pip。

You should consider upgrading via the 'pip install --upgrade pip' comma ...

谢谢,这个帖子之前没通过审核。。
我在这里问了
https://fishc.com.cn/forum.php?mod=viewthread&tid=150843&page=2#pid4195494

最后我决定用spyder运行代码,没报错{:10_262:}

页: [1]
查看完整版本: No module named 'matplotlib'