简体   繁体   English

如何使用Python3.2安装matplotlib

[英]How to install matplotlib with Python3.2

I installed python3.2 in ubuntu (the default edition is not deleted), and I follow the steps in here 我在ubuntu中安装了python3.2(默认版本没有删除),我按照这里的步骤操作

However when i use 但是,当我使用

python3.2 setup.py install

I got: 我有:

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

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

Matplotlib supports python 3.x as of version 1.2, released in January, 2013. Matplotlib支持2013年1月发布的1.2版本的python 3.x.

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). 通常,调用pip install matplotlib或使用您的首选机制( condahomebrew ,windows installer,系统软件包管理器等)。 In some cases you may need to install additional non-python dependencies ( libpng and freetype ) through your system's package manager. 在某些情况下,您可能需要通过系统的包管理器安装其他非python依赖项( libpngfreetype )。

The answer below is left for historical reasons and as an example of installing the development version from github. 下面的答案是出于历史原因以及从github安装开发版本的示例。


The current release of matplotlib doesn't support python3. matplotlib的当前版本不支持python3。

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. 几年来,python3支持有一个github分支,但直到最近才在linux以外的任何东西上保持稳定。 I believe that branch was recently merged back into the main branch. 我相信该分支最近被合并回主分支。

If you want to use matplotlib on python3, you'll need to build from the current tip https://github.com/matplotlib/matplotlib 如果你想在python3上使用matplotlib,你需要从当前的提示构建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

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 如果您没有安装git,那么您只需下载当前git提示的tarball: https//github.com/matplotlib/matplotlib/tarball/master

You'll need to have numpy installed for python3. 你需要为python3安装numpy。 (Installing it for python2 doesn't install it for python3.) (为python2安装它不会为python3安装它。)

In most cases, that's all you'll need to do. 在大多数情况下,这就是你需要做的全部。 For a default install, the only non-included python library is numpy. 对于默认安装,唯一不包含的python库是numpy。 The other dependencies (eg libpng , freetype ) are system libraries and if you can build matplotlib for python2, you already have them. 其他依赖项(例如libpngfreetype )是系统库,如果你可以为python2构建matplotlib,你已经有了它们。

If you want a non-default install (eg 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. 如果您想要非默认安装(例如,如果您想要任何非默认后端),那么您需要将setup.cfg.default模板复制到setup.cfg并编辑它以匹配您想要的。 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. 如果你打算在你正在编写的gtk或qt应用程序中嵌入matplotlib,你可能只需要这样做,在这种情况下你需要gtkaggqtagg后端而不是默认的tkagg后端。

just to bump @endolith's comment up to answer level, from at least uBuntu 14-04 linux onwards, matplotlib support for python3 is built-in with apt: 只是为了将@ endolith的评论提升到答案级别,至少从uBuntu 14-04 linux开始,matplotlib对python3的支持是内置的apt:

sudo apt-get install python3-matplotlib

should install matplotlib for python3 with the necessary dependencies. 应该为python3安装具有必要依赖性的matplotlib。

sudo apt-get build-dep python-matplotlib

这应该获得安装matplotlib所需的所有依赖项

Try Unofficial Windows Binaries for Python Extension Packages if you are running windows. 如果您正在运行Windows,请尝试用于Python扩展包的非官方Windows二进制文件。 http://www.lfd.uci.edu/~gohlke/pythonlibs/ http://www.lfd.uci.edu/~gohlke/pythonlibs/

I have followed the steps by Joe Kington on Ubuntu 14.04. 我在Ubuntu 14.04上按照Joe Kington的步骤进行操作。 Though those steps got me get started ran into few issues. 虽然这些步骤让我开始遇到了一些问题。 I had to do the following additional steps. 我不得不做以下额外的步骤。 Hope it helps someone else who has similar problems. 希望它可以帮助其他有类似问题的人。

  1. Install freetype package using 使用安装freetype包

      sudo apt-get install libfreetype6-dev 
  2. I had to install g++ because of this error: error trying to exec 'cc1plus': execvp: No such file or directory 因为这个错误我不得不安装g ++: 错误试图执行'cc1plus':execvp:没有这样的文件或目录

      sudo apt-get install g++ 
  3. Then I have to install python3.4-dev because of : fatal error: Python.h: No such file or directory 然后我必须安装python3.4-dev,因为: 致命错误:Python.h:没有这样的文件或目录

      sudo apt-get install python3.4-dev 

Now run the steps from Joe Kington . 现在运行Joe Kington的步骤。 This worked for me. 这对我有用。

It's simplicity itself. 它本身就很简单。

sudo pip install matplotlib will do the trick. sudo pip install matplotlib会做的伎俩。

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

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