简体   繁体   English

Python:无法在Mac上为matplotlib安装pyparsing

[英]Python: Can't install pyparsing for matplotlib on Mac

I am trying to install Matplotlib for Python on Mac. 我正在尝试在Mac上为Python安装Matplotlib First it threw an error stating that dateutil is not installed. 首先,它抛出一个错误,指出未安装dateutil After I installed that, I got the error message that pyparsing should be installed first. 安装完之后,我得到了错误消息, pyparsing应该首先安装pyparsing So I started to download pyparsing and tried to install it, as per the instructions at http://pyparsing.wikispaces.com/Download+and+Installation . 因此,我开始下载pyparsing并尝试按照http://pyparsing.wikispaces.com/Download+and+Installation上的说明进行安装。 However, I am getting the following error message: 但是,我收到以下错误消息:

在此处输入图片说明

Any help regarding this? 有什么帮助吗? Plus, what else do I need to install Matplotlib? 另外,我还需要安装Matplotlib吗? I have been trying for hours, first I was getting an error message like gcc is required when I was trying to download through pip . 我已经尝试了好几个小时,首先当我尝试通过pip下载时,我收到一条错误消息,例如gcc is required Then I left that and installed it through the pkg file. 然后我离开了,并通过pkg文件安装了它。 It succeeded, but when I try to import matplotlib I get these messages like dateutil required , then pyparsing required .. 它成功了,但是当我尝试import matplotlib我得到了诸如dateutil required类的消息,然后pyparsing required ..

Update: 更新:

Following the answer below, I installed a lower version of pyparsing compatible with Python 2.7, and now import matplotlib works. 按照以下答案,我安装了与Python 2.7兼容的较低版本的pyparsing ,现在可以import matplotlib However, still when I am trying to get a dispersion plot from NLTK , I am getting a matplotlib missing error: 但是,当我尝试从NLTK获取分散图时,仍然出现matplotlib missing错误:

在此处输入图片说明

Specifically, although import matplotlib works fine and throws no error, when I try something like import matplotlib.pyplot as pl I get this error: 具体来说,尽管import matplotlib可以正常工作并且不会引发任何错误,但是当我尝试使用诸如import matplotlib.pyplot as pl遇到了以下错误:

在此处输入图片说明

The error you're seeing is a Python 3 language feature (nonlocal), and you must be using Python 2 to run the setup script. 您看到的错误是Python 3语言功能(非本地),您必须使用Python 2运行安装脚本。 You'll need a version of PyParsing that is 2.x compatible to install instead (assuming you're trying to use Python 2.x). 您需要安装兼容2.x的PyParsing版本(假设您尝试使用Python 2.x)。

If you want to build / install python packages that have C-extensions, you should install Xcode , and then the command line tools (used to be a separate download, now it is available in-program from a preference pane). 如果要构建/安装具有C扩展名的python软件包,则应先安装Xcode ,然后安装命令行工具(以前是单独下载,现在可以从首选项窗格中以程序方式使用)。 Then you'll have a compiler installed, which is needed to build any python packages that require c-extensions to be compiled. 然后,您将安装一个编译器,该编译器是构建需要编译c扩展名的所有python包所必需的。

You can then use pip to install your package and its dependencies automatically, and build the required c-extensions. 然后,您可以使用pip自动安装软件包及其依赖项,并构建所需的c扩展名。

Alternatively, you could install the Enthought Python Distribution , which comes with matplotlib, numpy, scipy, and other scientific computing packages pre-built. 或者,您可以安装Enthought Python发行版 ,该发行版随附了matplotlib,numpy,scipy和其他预先构建的科学计算软件包。 This would be a different python interpreter / install area on your computer, which you would need to use instead of the version Apple ships with OS X. 这将是计算机上不同的python解释器/安装区域,您需要使用它而不是Apple随OS X附带的版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM