Install Matplotlib On Mac



How to install Python with NumPy, SciPy, Matplotlib on macOS Big Sur Apple Silicon M1.The procedure presented in the video should work on both Apple Silicon. In this tutorial, we will learn about installing matplotlib on different operating systems like windows and mac os, we will also have a brief look at how to work with matplotlib in jupyter notebook. In order to start working with matplotlib, we need to make sure it’s installed first on our system. This page provides the instructions for how to install and run IPython and Jupyter Notebook in a virtualenv on Mac. Most probably your Mac has already come with Python installed (see step 1 and step 2 below to check whether Python and Python 3 is installed on your mac, because my Mac book air has both Python and Python3.6 installed, I will go ahead to step 3 to install virtualenv).

Question or issue on macOS:

Matplotlib

I was trying to install matplotlib in Mac OSX Lion. Tried to used the binary that is in the sourcefourge site, but I got this error: “matplotlib requires System Python 2.7 to install”.

InstallInstall

I went to the Terminal and typed python –version and its check the requirements.

  1. Matplotlib: Installation/Set-up This is a short tutorial on how to install Matplotlib in macOS (10.4/Mojave). We will use the pip package installer for Python. First, we securely download get-pip.py, a bootstrapping script which enables users to install pip, setuptools and wheel in the Python environment.
  2. Although you can use a package manager like MacPorts or homebrew to install matplotlib on OS X, if you are interested in a method that uses only the XCode-provided freetype and libpng libraries, see my answer to a related question here.– mhowisonJun 1 '12 at 2:09 Add a comment 2 Answers 2.

After this I tried to used the pip, and while doing so é got the following error:

“src/_image.cpp:908: error: invalid use of incomplete type ‘struct png_info_def’”

Can you give me clues in how to install it?

Many thanks.

EDIT: I found a way, without having to install a new version of python:

http://the.taoofmac.com/space/blog/2011/07/24/2222

How to solve this problem?

Solution no. 1:

You can try with an “official” python distribution, apple might have tweaked the supplied one. You can find the 2.7 here: http://www.python.org/download/
You might have to re-install numpy as well afterwords: http://sourceforge.net/projects/numpy/files/NumPy/1.6.1/

I would suggest to install scipy as well
Let me know if it works 😉

Solution no. 2:

This is because of a change in the API for libpng v1.5 (which is included with Mac OSX Lion). The changes has already been pushed upstream, so you will need to compile from the upstream repository until the next release.

You can follow the instructions on http://jholewinski.wordpress.com/2011/07/21/installing-matplotlib-on-os-x-10-7-with-homebrew/

Solution no. 3:

I followed this page’s instructions. I got stuck at

Then I did:

Checked my installation by typing in terminal:

I got version 0.10.0 dev (as of this writing) and path /usr/local/Cellar/…

Solution no. 4:

I would recommend using macports, it should take care of dependencies and would be indepedent of the system python version.

EDIT: Just a few clarifications, taking into account comments to this answer.

Why use macports (or another installer)? Because they take care of dependencies, provide functionality to uninstall and switch between versions (I’ve used the latter successfully for gcc and python). And because the default installation location is not the system executable location. Overriding the system python can break applications that rely on it (this is certainly true in many Linux distributions, maybe less so on mac OS X).

When is it particularly useful? When you want to install on top of a version of python that is different to system python, and when you have non-python extensions (C, C++, Fortran…).

What’s the down side? As @Trond has mentioned in the comments, it is good if you’re OK with default compilations of packages. You don’t have a handle over configuration or compiler flags as you would if you built from source.

A good alternative to macports is fink, which seems to give you more control (build from source). I am not sure it is completely ready for mac OS X Lion yet.

Solution no. 5:

Install

I know it will take a lot more time, but I would reccomend installing python, numpy, and matplotlib from source to ensure that you have consistency in your system. From the error it could look like you have a problem with libPNG support. I have a written a “How to install python dev tools on Mac OSX” that you may find useful. It contains directions for how to install python, numpy, matplotlib and all necessary dependencies. I understand you are working with Python 2.7 and the directions I am listing is for Python 2.6.5, but it would be the same approach. Hope you get it to work.

How To Install Matplotlib Idle

Solution no. 6:

You could just install the Python 2.6 version of Matplotlib, assuming that Python2.6 is included with Lion (py2.5 & 2.6 are included with Mac OS 10.6 “Snow Leopard” – try typing python2.6 to find out if that version is installed.).

On MacPorts you do this via something like:

where py26-… (or py25-…, py27-… etc.) indicates which python version it is meant for. (check the Pallet/ports list to get the correct package name, in case I guessed wrong)

Hope this helps!

On OSX, two different types of Python builds exist: a regular build and aframework build. In order to interact correctly with OSX through the nativeGUI frameworks, you need a framework build of Python. At the time of writingthe macosx and WXAgg backends require a framework build to functioncorrectly. This can result in issues for a Python installation not build as aframework and may also happen in virtual envs and when using (Ana)conda. FromMatplotlib 1.5 onwards, both backends check that a framework build is availableand fail if a non framework build is found. (Without this check a partiallyfunctional figure is created. In particular, it is produced in the backgroundand cannot be put in front of any other window.)

virtualenv¶

Install Matplotlib Mac Brew

In a virtualenv, a non-framework build is used even when the environment iscreated from a framework build (virtualenv bug #54, virtualenv bug #609).

Install Pylab On Mac

The solution is to not use virtualenv, but instead the stdlib's venv, whichprovides similar functionality but without exhibiting this issue.

If you absolutely need to use virtualenv rather than venv, then from withinthe environment you can set the PYTHONHOME environment variable to$VIRTUAL_ENV, then invoke Python using the full path to the framework build(typically /usr/local/bin/python).

conda¶

Install Pip Macos Catalina

The default python provided in (Ana)conda is not a framework build. However,a framework build can easily be installed, both in the main environment andin conda envs: install python.app (condainstallpython.app) and usepythonw rather than python.