如何使用Python3.2安装matplotlib [英] How to install matplotlib with Python3.2

查看:230
本文介绍了如何使用Python3.2安装matplotlib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ubuntu中安装了python3.2(未删除默认版本),并且按照此处

I installed python3.2 in ubuntu (the default edition is not deleted), and I follow the steps in here

但是当我使用

python3.2 setup.py install

我得到了:

 "error: command 'gcc' failed with exit status 1",
"src/ft2font.cpp:2224:29: error: ‘Int’ is not a member of ‘Py’"

当我使用 sudo apt-get install python-matplotlib 我可以在python2.x中使用matplot,而我仍然无法在python3.2中使用它 如何在python3.2中安装matplot?

And when I use sudo apt-get install python-matplotlib I can use matplot in python2.x, while I still can not use it with python3.2 How can I install matplot in python3.2 ?

推荐答案

Matplotlib自2013年1月发布的1.2版开始支持python 3.x.

Matplotlib supports python 3.x as of version 1.2, released in January, 2013.

要安装它,请查看安装说明.通常,调用pip install matplotlib或使用您喜欢的机制(condahomebrew,Windows安装程序,系统软件包管理器等).在某些情况下,您可能需要通过系统的程序包管理器安装其他非python依赖项(libpngfreetype).

To install it, have a look at the installation instructions. In general, call pip install matplotlib or use your preferred mechanism (conda, homebrew, windows installer, system package manager, etc). In some cases you may need to install additional non-python dependencies (libpng and freetype) through your system's package manager.

下面的答案出于历史原因,并作为从github安装开发版本的示例.

The answer below is left for historical reasons and as an example of installing the development version from github.

当前版本的matplotlib不支持python3.

The current release of matplotlib doesn't support python3.

已经有一个支持python3的github分支了,但是直到最近才在Linux以外的任何其他版本上保持稳定.我相信该分支最近已合并回主分支.

There's a github branch for python3 support for a couple of years now, but it hasn't been stable on anything other than linux until fairly recently. I believe that branch was recently merged back into the main branch.

如果要在python3上使用matplotlib,则需要从当前提示构建 https://github.com/matplotlib/matplotlib

If you want to use matplotlib on python3, you'll need to build from the current tip https://github.com/matplotlib/matplotlib

要构建它,请执行以下操作:

To build it, do something similar to the following:

git clone https://github.com/matplotlib/matplotlib
cd matplotlib
python3 setup.py build
sudo python3 setup.py install

如果您尚未安装git,则可以直接下载当前git提示的tarball: https: //github.com/matplotlib/matplotlib/tarball/master

If you don't have git installed, then you can just download a tarball of the current git tip instead: https://github.com/matplotlib/matplotlib/tarball/master

您需要为python3安装numpy. (为python2安装不会为python3安装.)

You'll need to have numpy installed for python3. (Installing it for python2 doesn't install it for python3.)

在大多数情况下,这就是您需要做的.对于默认安装,唯一不包含的python库是numpy.其他依赖项(例如libpngfreetype)是系统库,如果您可以为python2构建matplotlib,则已经拥有它们.

In most cases, that's all you'll need to do. For a default install, the only non-included python library is numpy. The other dependencies (e.g. libpng, freetype) are system libraries and if you can build matplotlib for python2, you already have them.

如果要进行非默认安装(例如,如果要使用任何非默认后端),则需要将setup.cfg.default模板复制到setup.cfg并对其进行编辑以匹配所需的内容.如果您打算将matplotlib嵌入正在编写的gtk或qt应用程序中,则可能只需要执行此操作,在这种情况下,您将需要gtkaggqtagg后端,而不仅仅是默认值tkagg后端.

If you want a non-default install (e.g. if you want any of the non-default backends), then you'll need to copy the setup.cfg.default template to setup.cfg and edit it to match what you want. You'll probably only need to do this if you're planning to embed matplotlib in a gtk or qt application that you're writing, in which case you'll want the gtkagg or qtagg backends instead of just the default tkagg backend.

这篇关于如何使用Python3.2安装matplotlib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆