mac安装numpy,scipy,matplotlib

Posted 小码哥0520

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mac安装numpy,scipy,matplotlib相关的知识,希望对你有一定的参考价值。

 
SaintKings-Mac-mini:~ saintking$ python
Python 2.7.10 (default, Jul 30 2016, 18:31:42) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> help()

Welcome to Python 2.7!  This is the online help utility.

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/2.7/tutorial/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, or topics, type "modules",
"keywords", or "topics".  Each module also comes with a one-line summary
of what it does; to list the modules whose summaries contain a given word
such as "spam", type "modules spam".

help> numpy
View Code

>>> import numpy as np

>>> np.multiply(1,3)

3

>>> 

numpy安装是完成的.

1.安装numpy

2.安装scipy

3.安装matplotlib

help> scipy

 

help> matplotlib

经检查都已经安装成功.

测试一下:

>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/pyplot.py", line 29, in <module>
    from matplotlib.figure import Figure, figaspect
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/figure.py", line 36, in <module>
    from matplotlib.axes import Axes, SubplotBase, subplot_class_factory
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/axes.py", line 20, in <module>
    import matplotlib.dates as _  # <-registers a date unit converter
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/dates.py", line 119, in <module>
    from dateutil.rrule import (rrule, MO, TU, WE, TH, FR, SA, SU, YEARLY,
  File "/Users/saintking/Library/Python/2.7/lib/python/site-packages/dateutil/rrule.py", line 19, in <module>
    from six.moves import _thread, range
ImportError: cannot import name _thread
View Code

解决一下这个问题.

因为python的版本太低.现在采用3.6

SaintKings-Mac-mini:~ saintking$ which python

/usr/bin/python

 

mv /usr/bin/python /usr/bin/python_backup

mv /usr/local/bin/python /usr/local/bin/python_backup

>>> import matplotlib.pyplot as plt

 

在很多时候我们希望忽略过去下载的安装包,直接下载安装可以使用–ignore-installed这个参数,比如我发现的的matplotlib的mplot3d部分有点问题,我想再重新下载安装一遍,可以这么做

这会把相关的包(numpy, pytz, six, python-dateutil, cycler, pyparsing, matplotlib)都下载安装一遍

SaintKings-Mac-mini:~ saintking$ sudo pip install --upgrade --ignore-installed matplotlib

Password:

The directory \'/Users/saintking/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.

The directory \'/Users/saintking/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 matplotlib-2.1.0-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (13.2MB)

    100% |████████████████████████████████| 13.2MB 77kB/s 

Collecting pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 (from matplotlib)

  Downloading pyparsing-2.2.0-py2.py3-none-any.whl (56kB)

    100% |████████████████████████████████| 61kB 901kB/s 

Collecting numpy>=1.7.1 (from matplotlib)

  Downloading numpy-1.13.3-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (4.6MB)

    100% |████████████████████████████████| 4.6MB 164kB/s 

Collecting pytz (from matplotlib)

  Downloading pytz-2017.2-py2.py3-none-any.whl (484kB)

    100% |████████████████████████████████| 491kB 442kB/s 

Collecting backports.functools-lru-cache (from matplotlib)

  Downloading backports.functools_lru_cache-1.4-py2.py3-none-any.whl

Collecting six>=1.10 (from matplotlib)

  Downloading six-1.11.0-py2.py3-none-any.whl

Collecting cycler>=0.10 (from matplotlib)

  Downloading cycler-0.10.0-py2.py3-none-any.whl

Collecting subprocess32 (from matplotlib)

  Downloading subprocess32-3.2.7.tar.gz (54kB)

    100% |████████████████████████████████| 61kB 599kB/s 

Collecting python-dateutil>=2.0 (from matplotlib)

  Downloading python_dateutil-2.6.1-py2.py3-none-any.whl (194kB)

    100% |████████████████████████████████| 194kB 522kB/s 

Installing collected packages: pyparsing, numpy, pytz, backports.functools-lru-cache, six, cycler, subprocess32, python-dateutil, matplotlib

  Running setup.py install for subprocess32 ... done

Successfully installed backports.functools-lru-cache-1.4 cycler-0.10.0 matplotlib-2.1.0 numpy-1.13.3 pyparsing-2.2.0 python-dateutil-2.6.1 pytz-2017.2 six-1.11.0 subprocess32-3.2.7

SaintKings-Mac-mini:~ saintking$ python

Python 2.7.10 (default, Jul 30 2016, 18:31:42) 

[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

>>> import matplotlib.pyplot as plt

>>> plt.bar(left=(0,1),height=(1,0.5))

/Library/Python/2.7/site-packages/matplotlib/__init__.py:1710: MatplotlibDeprecationWarning: The *left* kwarg to `bar` is deprecated use *x* instead. Support for *left* will be removed in Matplotlib 3.0

  return func(ax, *args, **kwargs)

<Container object of 2 artists>

>>> plt.show()

>>> 

显示出来:

 

 

以上是关于mac安装numpy,scipy,matplotlib的主要内容,如果未能解决你的问题,请参考以下文章

Python 学习之中的一个:在Mac OS X下基于Sublime Text搭建开发平台包括numpy,scipy

在 Mac 上安装 Python 包/模块

Linux 下安装 numpy 和 scipy

Ubuntu 16.04(x64)内安装lightgbm前的准备工作

Mac配置虚拟环境Virtualenv

如何改变anaconda 的 gcc 版本